info.vue 12 KB

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