info.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <s-layout 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. >修改</button
  29. >
  30. <!-- #endif -->
  31. <!-- #ifndef MP -->
  32. <button class="ss-reset-button avatar-action-btn" @tap="onChangeAvatar">修改</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="用户名" @tap="onChangeUsername" class="label-box">
  39. <uni-easyinput
  40. v-model="userInfo.username"
  41. disabled
  42. :inputBorder="false"
  43. :styles="{ disableColor: '#fff' }"
  44. placeholder="设置用户名"
  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="昵称">
  57. <uni-easyinput
  58. v-model="state.model.nickname"
  59. type="nickname"
  60. placeholder="设置昵称"
  61. :inputBorder="false"
  62. :placeholderStyle="placeholderStyle"
  63. />
  64. </uni-forms-item>
  65. <uni-forms-item name="gender" label="性别">
  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="手机号" @tap="onChangeMobile">
  83. <uni-easyinput
  84. v-model="userInfo.mobile"
  85. placeholder="请绑定手机号"
  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="登录密码" @tap="onSetPassword">
  103. <uni-easyinput
  104. v-model="userInfo.password"
  105. :placeholder="userInfo.verification?.password ? '修改登录密码' : '点击设置登录密码'"
  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="地址管理"
  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="发票管理"
  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">第三方账号绑定</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="sheep.$url.static('/static/img/shop/platform/WechatOfficialAccount.png')"
  155. />
  156. <text class="list-name">微信公众号</text>
  157. </view>
  158. <view v-if="'WechatMiniProgram' === sheep.$platform.name" class="ss-flex ss-col-center">
  159. <image
  160. class="list-img"
  161. :src="sheep.$url.static('/static/img/shop/platform/WechatMiniProgram.png')"
  162. />
  163. <text class="list-name">微信小程序</text>
  164. </view>
  165. <view v-if="'App' === sheep.$platform.name" class="ss-flex ss-col-center">
  166. <image
  167. class="list-img"
  168. :src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
  169. />
  170. <text class="list-name">微信开放平台</text>
  171. </view>
  172. <view class="ss-flex ss-col-center">
  173. <view class="info ss-flex ss-col-center" v-if="state.thirdOauthInfo">
  174. <image
  175. class="avatar ss-m-r-20"
  176. :src="sheep.$url.cdn(state.thirdOauthInfo.avatar)"
  177. ></image>
  178. <text class="name">{{ state.thirdOauthInfo.nickname }}</text>
  179. </view>
  180. <view class="bind-box ss-m-l-20">
  181. <button
  182. v-if="state.thirdOauthInfo"
  183. class="ss-reset-button relieve-btn"
  184. @tap="unBindThirdOauth"
  185. >
  186. 解绑
  187. </button>
  188. <button v-else class="ss-reset-button bind-btn" @tap="bindThirdOauth">绑定</button>
  189. </view>
  190. </view>
  191. </view>
  192. </view>
  193. <su-fixed bottom placeholder bg="none">
  194. <view class="footer-box ss-p-20">
  195. <button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">保存</button>
  196. </view>
  197. </su-fixed>
  198. </s-layout>
  199. </template>
  200. <script setup>
  201. import { computed, ref, reactive, onBeforeMount, unref } from 'vue';
  202. import { mobile, password, username } from '@/sheep/validate/form';
  203. import sheep from '@/sheep';
  204. import { clone } from 'lodash';
  205. import { showAuthModal } from '@/sheep/hooks/useModal';
  206. const state = reactive({
  207. model: {},
  208. rules: {},
  209. thirdOauthInfo: null,
  210. });
  211. const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
  212. const genderRadioMap = [
  213. {
  214. name: '男',
  215. value: '1',
  216. },
  217. {
  218. name: '女',
  219. value: '2',
  220. },
  221. {
  222. name: '未知',
  223. value: '0',
  224. },
  225. ];
  226. const userInfo = computed(() => sheep.$store('user').userInfo);
  227. // 选择性别
  228. function onChangeGender(e) {
  229. state.model.gender = e.detail.value;
  230. }
  231. // 修改用户名
  232. const onChangeUsername = () => {
  233. !state.model.verification?.username && showAuthModal('changeUsername');
  234. };
  235. // 修改手机号
  236. const onChangeMobile = () => {
  237. showAuthModal('changeMobile');
  238. };
  239. function onChooseAvatar(e) {
  240. const tempUrl = e.detail.avatarUrl || '';
  241. uploadAvatar(tempUrl);
  242. }
  243. //修改头像
  244. function onChangeAvatar() {
  245. uni.chooseImage({
  246. success: async (chooseImageRes) => {
  247. const tempUrl = chooseImageRes.tempFilePaths[0];
  248. uploadAvatar(tempUrl);
  249. },
  250. });
  251. }
  252. async function uploadAvatar(tempUrl) {
  253. if (!tempUrl) return;
  254. let { path } = await sheep.$api.app.upload(tempUrl, 'ugc');
  255. state.model.avatar = path;
  256. }
  257. // 修改/设置密码
  258. function onSetPassword() {
  259. if (state.model.verification.password) {
  260. showAuthModal('changePassword');
  261. } else {
  262. showAuthModal('resetPassword');
  263. }
  264. }
  265. // 绑定第三方账号
  266. async function bindThirdOauth() {
  267. let result = await sheep.$platform.useProvider('wechat').bind();
  268. if (result) {
  269. getUserInfo();
  270. }
  271. }
  272. // 解绑第三方账号
  273. function unBindThirdOauth() {
  274. uni.showModal({
  275. title: '解绑提醒',
  276. content: '解绑后您将无法通过微信登录此账号',
  277. cancelText: '再想想',
  278. confirmText: '确定',
  279. success: async function (res) {
  280. if (res.confirm) {
  281. const result = await sheep.$platform.useProvider('wechat').unbind();
  282. if (result) {
  283. getUserInfo();
  284. }
  285. }
  286. },
  287. });
  288. }
  289. // 保存信息
  290. async function onSubmit() {
  291. const { error, data } = await sheep.$api.user.update({
  292. avatar: state.model.avatar,
  293. nickname: state.model.nickname,
  294. gender: state.model.gender,
  295. });
  296. if (error === 0) {
  297. getUserInfo();
  298. }
  299. }
  300. const getUserInfo = async () => {
  301. const userInfo = await sheep.$store('user').getInfo();
  302. state.model = clone(userInfo);
  303. if (sheep.$platform.name !== 'H5') {
  304. let { data, error } = await sheep.$api.user.thirdOauthInfo();
  305. if (error === 0) {
  306. state.thirdOauthInfo = data;
  307. }
  308. }
  309. };
  310. onBeforeMount(async () => {
  311. getUserInfo();
  312. });
  313. </script>
  314. <style lang="scss" scoped>
  315. :deep() {
  316. .uni-file-picker {
  317. border-radius: 50%;
  318. }
  319. .uni-file-picker__container {
  320. margin: -14rpx -12rpx;
  321. }
  322. .file-picker__progress {
  323. height: 0 !important;
  324. }
  325. .uni-list-item__content-title {
  326. font-size: 28rpx !important;
  327. color: #333333 !important;
  328. line-height: normal !important;
  329. }
  330. .uni-icons {
  331. font-size: 40rpx !important;
  332. }
  333. .is-disabled {
  334. color: #333333;
  335. }
  336. }
  337. :deep(.disabled) {
  338. opacity: 1;
  339. }
  340. .gender-name {
  341. font-size: 28rpx;
  342. font-weight: 500;
  343. line-height: normal;
  344. color: #333333;
  345. }
  346. .title-box {
  347. font-size: 28rpx;
  348. font-weight: 500;
  349. color: #666666;
  350. line-height: 100rpx;
  351. }
  352. .logout-btn {
  353. width: 710rpx;
  354. height: 80rpx;
  355. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  356. border-radius: 40rpx;
  357. font-size: 30rpx;
  358. font-weight: 500;
  359. color: $white;
  360. }
  361. .radio-dark {
  362. filter: grayscale(100%);
  363. filter: gray;
  364. opacity: 0.4;
  365. }
  366. .content-img {
  367. border-radius: 50%;
  368. }
  369. .header-box-content {
  370. position: relative;
  371. width: 160rpx;
  372. height: 160rpx;
  373. overflow: hidden;
  374. border-radius: 50%;
  375. }
  376. .avatar-action {
  377. position: absolute;
  378. left: 50%;
  379. transform: translateX(-50%);
  380. bottom: 0;
  381. z-index: 1;
  382. width: 160rpx;
  383. height: 46rpx;
  384. background: rgba(#000000, 0.3);
  385. .avatar-action-btn {
  386. width: 160rpx;
  387. height: 46rpx;
  388. font-weight: 500;
  389. font-size: 24rpx;
  390. color: #ffffff;
  391. }
  392. }
  393. // 绑定项
  394. .account-list {
  395. background-color: $white;
  396. height: 100rpx;
  397. padding: 0 20rpx;
  398. .list-img {
  399. width: 40rpx;
  400. height: 40rpx;
  401. margin-right: 10rpx;
  402. }
  403. .list-name {
  404. font-size: 28rpx;
  405. color: #333333;
  406. }
  407. .info {
  408. .avatar {
  409. width: 38rpx;
  410. height: 38rpx;
  411. border-radius: 50%;
  412. overflow: hidden;
  413. }
  414. .name {
  415. font-size: 28rpx;
  416. font-weight: 400;
  417. color: $dark-9;
  418. }
  419. }
  420. .bind-box {
  421. width: 100rpx;
  422. height: 50rpx;
  423. line-height: normal;
  424. display: flex;
  425. justify-content: center;
  426. align-items: center;
  427. font-size: 24rpx;
  428. .bind-btn {
  429. width: 100%;
  430. height: 100%;
  431. border-radius: 25rpx;
  432. background: #f4f4f4;
  433. color: #999999;
  434. }
  435. .relieve-btn {
  436. width: 100%;
  437. height: 100%;
  438. border-radius: 25rpx;
  439. background: var(--ui-BG-Main-opacity-1);
  440. color: var(--ui-BG-Main);
  441. }
  442. }
  443. }
  444. .list-border {
  445. font-size: 28rpx;
  446. font-weight: 400;
  447. color: #333333;
  448. border-bottom: 2rpx solid #eeeeee;
  449. }
  450. image {
  451. width: 100%;
  452. height: 100%;
  453. }
  454. </style>