info.vue 13 KB

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