info.vue 13 KB

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