info.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <s-layout :title="$t('user.info.title')" class="set-userinfo-wrap">
  3. <uni-forms
  4. :model="state.model"
  5. :rules="state.rules"
  6. labelPosition="left"
  7. border
  8. class="form-box"
  9. >
  10. <view class="ss-flex ss-row-center ss-col-center ss-p-t-60 ss-p-b-0 bg-white">
  11. <view class="header-box-content">
  12. <su-image
  13. class="content-img"
  14. isPreview
  15. :current="0"
  16. :src="sheep.$url.cdn(state.model.avatar)"
  17. :height="160"
  18. :width="160"
  19. :radius="80"
  20. mode="scaleToFill"
  21. ></su-image>
  22. <view class="avatar-action">
  23. <!-- #ifdef MP -->
  24. <button
  25. class="ss-reset-button avatar-action-btn"
  26. open-type="chooseAvatar"
  27. @chooseavatar="onChooseAvatar"
  28. >{{$t('user.info.edit')}}</button
  29. >
  30. <!-- #endif -->
  31. <!-- #ifndef MP -->
  32. <button class="ss-reset-button avatar-action-btn" @tap="onChangeAvatar">{{$t('user.info.edit')}}</button>
  33. <!-- #endif -->
  34. </view>
  35. </view>
  36. </view>
  37. <view class="bg-white ss-p-x-30">
  38. <uni-forms-item name="username" :label="$t('user.info.username')" @tap="onChangeUsername" class="label-box">
  39. <uni-easyinput
  40. v-model="userInfo.username"
  41. disabled
  42. :inputBorder="false"
  43. :styles="{ disableColor: '#fff' }"
  44. :placeholder="$t('user.info.setUsername')"
  45. :clearable="false"
  46. :placeholderStyle="placeholderStyle"
  47. >
  48. <template v-slot:right>
  49. <su-radio class="ss-flex" v-if="userInfo.verification?.username" :modelValue="true" />
  50. <button v-else class="ss-reset-button">
  51. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  52. </button>
  53. </template>
  54. </uni-easyinput>
  55. </uni-forms-item>
  56. <uni-forms-item name="nickname" :label="$t('user.info.nickname')">
  57. <uni-easyinput
  58. v-model="state.model.nickname"
  59. type="nickname"
  60. :placeholder="$t('user.info.setNickname')"
  61. :inputBorder="false"
  62. :placeholderStyle="placeholderStyle"
  63. />
  64. </uni-forms-item>
  65. <uni-forms-item name="gender" :label="$t('user.info.sex')">
  66. <view class="ss-flex ss-col-center ss-h-100">
  67. <radio-group @change="onChangeGender" class="ss-flex ss-col-center">
  68. <label class="radio" v-for="item in genderRadioMap" :key="item.value">
  69. <view class="ss-flex ss-col-center ss-m-r-32">
  70. <radio
  71. :value="item.value"
  72. color="var(--ui-BG-Main)"
  73. style="transform: scale(0.8)"
  74. :checked="item.value == state.model.gender"
  75. />
  76. <view class="gender-name">{{ item.name }}</view>
  77. </view>
  78. </label>
  79. </radio-group>
  80. </view>
  81. </uni-forms-item>
  82. <uni-forms-item name="mobile" :label="$t('user.info.mobile')" @tap="onChangeMobile">
  83. <uni-easyinput
  84. v-model="userInfo.mobile"
  85. :placeholder="$t('user.info.bindMobile')"
  86. :inputBorder="false"
  87. disabled
  88. :styles="{ disableColor: '#fff' }"
  89. :placeholderStyle="placeholderStyle"
  90. :clearable="false"
  91. >
  92. <template v-slot:right>
  93. <view class="ss-flex ss-col-center">
  94. <su-radio v-if="userInfo.verification?.mobile" :modelValue="true" />
  95. <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
  96. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  97. </button>
  98. </view>
  99. </template>
  100. </uni-easyinput>
  101. </uni-forms-item>
  102. <uni-forms-item name="password" :label="$t('user.info.password')" @tap="onSetPassword">
  103. <uni-easyinput
  104. v-model="userInfo.password"
  105. :placeholder="userInfo.verification?.password ? $t('user.info.editPassword') : $t('user.info.setPassword')"
  106. :inputBorder="false"
  107. :styles="{ disableColor: '#fff' }"
  108. disabled
  109. placeholderStyle="color:#BBBBBB;font-size:28rpx;line-height:normal"
  110. :clearable="false"
  111. >
  112. <template v-slot:right>
  113. <view class="ss-flex ss-col-center">
  114. <su-radio
  115. class="ss-flex"
  116. v-if="userInfo.verification?.password"
  117. :modelValue="true"
  118. />
  119. <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
  120. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  121. </button>
  122. </view>
  123. </template>
  124. </uni-easyinput>
  125. </uni-forms-item>
  126. </view>
  127. <view class="bg-white ss-m-t-14">
  128. <uni-list>
  129. <uni-list-item
  130. clickable
  131. @tap="sheep.$router.go('/pages/user/address/list')"
  132. :title="$t('user.info.address')"
  133. showArrow
  134. :border="false"
  135. class="list-border"
  136. ></uni-list-item>
  137. <uni-list-item
  138. clickable
  139. @tap="sheep.$router.go('/pages/user/invoice/list')"
  140. :title="$t('user.info.invoice')"
  141. showArrow
  142. :border="false"
  143. class="list-border"
  144. ></uni-list-item>
  145. </uni-list>
  146. </view>
  147. </uni-forms>
  148. <view v-if="sheep.$platform.name !== 'H5'">
  149. <view class="title-box ss-p-l-30">{{$t('user.info.thirdAccount')}}</view>
  150. <view class="account-list ss-flex ss-row-between">
  151. <view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center">
  152. <image
  153. class="list-img"
  154. :src="
  155. sheep.$url.static(
  156. '/assets/addons/shopro/uniapp/platform/WechatOfficialAccount.png',
  157. )
  158. "
  159. />
  160. <text class="list-name">{{$t('user.info.wxPublicAccount')}}</text>
  161. </view>
  162. <view v-if="'WechatMiniProgram' === sheep.$platform.name" class="ss-flex ss-col-center">
  163. <image
  164. class="list-img"
  165. :src="
  166. sheep.$url.static('/assets/addons/shopro/uniapp/platform/WechatMiniProgram.png')
  167. "
  168. />
  169. <text class="list-name">{{$t('user.info.wxApplet')}}</text>
  170. </view>
  171. <view v-if="'App' === sheep.$platform.name" class="ss-flex ss-col-center">
  172. <image
  173. class="list-img"
  174. :src="sheep.$url.static('/assets/addons/shopro/uniapp/platform/wechat.png')"
  175. />
  176. <text class="list-name">{{$t('user.info.wxOpenPlatform')}}</text>
  177. </view>
  178. <view class="ss-flex ss-col-center">
  179. <view class="info ss-flex ss-col-center" v-if="state.thirdOauthInfo">
  180. <image
  181. class="avatar ss-m-r-20"
  182. :src="sheep.$url.cdn(state.thirdOauthInfo.avatar)"
  183. ></image>
  184. <text class="name">{{ state.thirdOauthInfo.nickname }}</text>
  185. </view>
  186. <view class="bind-box ss-m-l-20">
  187. <button
  188. v-if="state.thirdOauthInfo"
  189. class="ss-reset-button relieve-btn"
  190. @tap="unBindThirdOauth"
  191. >
  192. {{$t('user.info.unbind')}}
  193. </button>
  194. <button v-else class="ss-reset-button bind-btn" @tap="bindThirdOauth">{{$t('user.info.bind')}}</button>
  195. </view>
  196. </view>
  197. </view>
  198. </view>
  199. <su-fixed bottom placeholder bg="none">
  200. <view class="footer-box ss-p-20">
  201. <button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">{{$t('user.info.save')}}</button>
  202. </view>
  203. </su-fixed>
  204. </s-layout>
  205. </template>
  206. <script setup>
  207. import { computed, ref, reactive, onBeforeMount, unref } from 'vue';
  208. import { mobile, password, username } from '@/sheep/validate/form';
  209. import sheep from '@/sheep';
  210. import { clone } from 'lodash';
  211. import { showAuthModal } from '@/sheep/hooks/useModal';
  212. const state = reactive({
  213. model: {},
  214. rules: {},
  215. thirdOauthInfo: null,
  216. });
  217. const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
  218. const genderRadioMap = [
  219. {
  220. name: $t('user.info.male'),
  221. value: '1',
  222. },
  223. {
  224. name: $t('user.info.female'),
  225. value: '0',
  226. },
  227. {
  228. name: $t('user.info.private'),
  229. value: '2',
  230. },
  231. ];
  232. const userInfo = computed(() => sheep.$store('user').userInfo);
  233. // 选择性别
  234. function onChangeGender(e) {
  235. state.model.gender = e.detail.value;
  236. }
  237. // 修改用户名
  238. const onChangeUsername = () => {
  239. !state.model.verification?.username && showAuthModal('changeUsername');
  240. };
  241. // 修改手机号
  242. const onChangeMobile = () => {
  243. showAuthModal('changeMobile');
  244. };
  245. function onChooseAvatar(e) {
  246. const tempUrl = e.detail.avatarUrl || '';
  247. uploadAvatar(tempUrl);
  248. }
  249. //修改头像
  250. function onChangeAvatar() {
  251. uni.chooseImage({
  252. success: async (chooseImageRes) => {
  253. const tempUrl = chooseImageRes.tempFilePaths[0];
  254. uploadAvatar(tempUrl);
  255. },
  256. });
  257. }
  258. async function uploadAvatar(tempUrl) {
  259. if (!tempUrl) return;
  260. let { url } = await sheep.$api.app.upload(tempUrl, 'ugc');
  261. state.model.avatar = url;
  262. }
  263. // 修改/设置密码
  264. function onSetPassword() {
  265. if (state.model.verification.password) {
  266. showAuthModal('changePassword');
  267. } else {
  268. showAuthModal('resetPassword');
  269. }
  270. }
  271. // 绑定第三方账号
  272. async function bindThirdOauth() {
  273. let result = await sheep.$platform.useProvider('wechat').bind();
  274. if (result) {
  275. getUserInfo();
  276. }
  277. }
  278. // 解绑第三方账号
  279. function unBindThirdOauth() {
  280. uni.showModal({
  281. title: $t('user.info.tips'),
  282. content: $t('user.info.tipsUnbind'),
  283. cancelText: $t('user.info.later'),
  284. confirmText: $t('user.info.confirm'),
  285. success: async function (res) {
  286. if (res.confirm) {
  287. const result = await sheep.$platform.useProvider('wechat').unbind();
  288. if (result) {
  289. getUserInfo();
  290. }
  291. }
  292. },
  293. });
  294. }
  295. // 保存信息
  296. async function onSubmit() {
  297. const { code, data } = await sheep.$api.user.update({
  298. avatar: state.model.avatar,
  299. nickname: state.model.nickname,
  300. gender: state.model.gender,
  301. });
  302. if (code === 1) {
  303. getUserInfo();
  304. }
  305. }
  306. const getUserInfo = async () => {
  307. const userInfo = await sheep.$store('user').getInfo();
  308. state.model = clone(userInfo);
  309. if (sheep.$platform.name !== 'H5') {
  310. let { data, code } = await sheep.$api.user.thirdOauthInfo();
  311. if (code === 1) {
  312. state.thirdOauthInfo = data;
  313. }
  314. }
  315. };
  316. onBeforeMount(async () => {
  317. getUserInfo();
  318. });
  319. </script>
  320. <style lang="scss" scoped>
  321. :deep() {
  322. .uni-file-picker {
  323. border-radius: 50%;
  324. }
  325. .uni-file-picker__container {
  326. margin: -14rpx -12rpx;
  327. }
  328. .file-picker__progress {
  329. height: 0 !important;
  330. }
  331. .uni-list-item__content-title {
  332. font-size: 28rpx !important;
  333. color: #333333 !important;
  334. line-height: normal !important;
  335. }
  336. .uni-icons {
  337. font-size: 40rpx !important;
  338. }
  339. .is-disabled {
  340. color: #333333;
  341. }
  342. }
  343. :deep(.disabled) {
  344. opacity: 1;
  345. }
  346. .gender-name {
  347. font-size: 28rpx;
  348. font-weight: 500;
  349. line-height: normal;
  350. color: #333333;
  351. }
  352. .title-box {
  353. font-size: 28rpx;
  354. font-weight: 500;
  355. color: #666666;
  356. line-height: 100rpx;
  357. }
  358. .logout-btn {
  359. width: 710rpx;
  360. height: 80rpx;
  361. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  362. border-radius: 40rpx;
  363. font-size: 30rpx;
  364. font-weight: 500;
  365. color: $white;
  366. }
  367. .radio-dark {
  368. filter: grayscale(100%);
  369. filter: gray;
  370. opacity: 0.4;
  371. }
  372. .content-img {
  373. border-radius: 50%;
  374. }
  375. .header-box-content {
  376. position: relative;
  377. width: 160rpx;
  378. height: 160rpx;
  379. overflow: hidden;
  380. border-radius: 50%;
  381. }
  382. .avatar-action {
  383. position: absolute;
  384. left: 50%;
  385. transform: translateX(-50%);
  386. bottom: 0;
  387. z-index: 1;
  388. width: 160rpx;
  389. height: 46rpx;
  390. background: rgba(#000000, 0.3);
  391. .avatar-action-btn {
  392. width: 160rpx;
  393. height: 46rpx;
  394. font-weight: 500;
  395. font-size: 24rpx;
  396. color: #ffffff;
  397. }
  398. }
  399. // 绑定项
  400. .account-list {
  401. background-color: $white;
  402. height: 100rpx;
  403. padding: 0 20rpx;
  404. .list-img {
  405. width: 40rpx;
  406. height: 40rpx;
  407. margin-right: 10rpx;
  408. }
  409. .list-name {
  410. font-size: 28rpx;
  411. color: #333333;
  412. }
  413. .info {
  414. .avatar {
  415. width: 38rpx;
  416. height: 38rpx;
  417. border-radius: 50%;
  418. overflow: hidden;
  419. }
  420. .name {
  421. font-size: 28rpx;
  422. font-weight: 400;
  423. color: $dark-9;
  424. }
  425. }
  426. .bind-box {
  427. width: 100rpx;
  428. height: 50rpx;
  429. line-height: normal;
  430. display: flex;
  431. justify-content: center;
  432. align-items: center;
  433. font-size: 24rpx;
  434. .bind-btn {
  435. width: 100%;
  436. height: 100%;
  437. border-radius: 25rpx;
  438. background: #f4f4f4;
  439. color: #999999;
  440. }
  441. .relieve-btn {
  442. width: 100%;
  443. height: 100%;
  444. border-radius: 25rpx;
  445. background: var(--ui-BG-Main-opacity-1);
  446. color: var(--ui-BG-Main);
  447. }
  448. }
  449. }
  450. .list-border {
  451. font-size: 28rpx;
  452. font-weight: 400;
  453. color: #333333;
  454. border-bottom: 2rpx solid #eeeeee;
  455. }
  456. image {
  457. width: 100%;
  458. height: 100%;
  459. }
  460. </style>