info.vue 13 KB

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