index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view :data-theme="'theme-' + proxy.$settingStore.themeColor.name" class="info-container">
  3. <u-sticky class="shadow-default" bgColor="#fff" style="top: 0">
  4. <u-tabs :list="tabsList" :current="tabsCurrent" @click="tabsClick" lineColor="#333" :activeStyle="{ color: '#333' }" :inactiveStyle="{ color: '#909399' }" :scrollable="false"></u-tabs>
  5. </u-sticky>
  6. <view class="content-section" v-show="tabsCurrent == 0">
  7. <view class="menu-list mt0 mlr0">
  8. <view class="list-cell list-cell-arrow" @click="proxy.$settingStore.handleToAvatar(2)">
  9. <view class="menu-item">
  10. <view class="title">头像</view>
  11. <image style="margin: 0 15px 0 auto" v-if="avatar" :src="avatar" class="cu-avatar radius"> </image>
  12. </view>
  13. </view>
  14. <view class="list-cell list-cell-arrow" @click="handleUserModal('修改昵称')">
  15. <view class="menu-item">
  16. <view class="title">昵称</view>
  17. <view class="content" style="margin: 0 15px 0 auto; font-size: 14px; color: #909399">{{ user.nickName }}</view>
  18. </view>
  19. </view>
  20. <view class="list-cell list-cell-arrow" @click="handleUserModal('修改手机号')">
  21. <view class="menu-item">
  22. <view class="title">手机号</view>
  23. <view style="margin: 0 15px 0 auto; font-size: 14px; color: #909399">{{ user.phonenumber }}</view>
  24. </view>
  25. </view>
  26. <view class="list-cell list-cell-arrow" @click="handleUserModal('修改邮箱')">
  27. <view class="menu-item">
  28. <view class="title">邮箱</view>
  29. <view style="margin: 0 15px 0 auto; font-size: 14px; color: #909399">{{ user.email }}</view>
  30. </view>
  31. </view>
  32. <view class="list-cell list-cell-arrow" @click="handleUserModal('修改性别')">
  33. <view class="menu-item">
  34. <view class="title">性别</view>
  35. <view style="margin: 0 15px 0 auto; font-size: 14px; color: #909399">{{ user.sex == "0" ? "男" : "女" }}</view>
  36. </view>
  37. </view>
  38. <view class="list-cell list-cell-arrow" @click="proxy.$modal.showToast('模块建设中~')">
  39. <view class="menu-item">
  40. <view class="title">我的名片</view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="menu-list mt0 mlr0">
  45. <view class="list-cell list-cell-arrow" @click="proxy.$modal.showToast('模块建设中~')">
  46. <view class="menu-item">
  47. <view>个人实名认证</view>
  48. </view>
  49. </view>
  50. <view class="list-cell list-cell-arrow" @click="proxy.$modal.showToast('模块建设中~')">
  51. <view class="menu-item">
  52. <view>更多</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- <view class="user-section" :class="'bg-' + proxy.$settingStore.themeColor.name" :style="{ paddingTop: proxy.$settingStore.barHightTop }">
  58. <image class="bg" src="@/static/images/mine/user-bg.png"></image>
  59. <view class="portrait-box">
  60. <image v-if="!avatar" @click="proxy.$settingStore.handleToAvatar(1)" class="portrait" src="@/static/images/mine/missing-face.png"></image>
  61. <image v-if="avatar" @click="proxy.$settingStore.handleToAvatar(2)" :src="avatar" class="portrait cu-avatar xl round"> </image>
  62. </view>
  63. </view> -->
  64. <!-- <uni-list>
  65. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'person-filled' }" title="昵称" :rightText="user.nickName" />
  66. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'phone-filled' }" title="手机号" :rightText="user.phonenumber" />
  67. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'email-filled' }" title="邮箱" :rightText="user.email" />
  68. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'auth-filled' }" title="岗位" :rightText="postGroup" />
  69. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'staff-filled' }" title="角色" :rightText="roleGroup" />
  70. <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'calendar-filled' }" title="创建日期" :rightText="user.createTime" />
  71. </uni-list> -->
  72. <!-- <view class="example">
  73. <uni-forms ref="form" :model="user" labelWidth="80px">
  74. <uni-forms-item label="用户昵称" name="nickName">
  75. <uni-easyinput v-model="user.nickName" placeholder="请输入昵称" />
  76. </uni-forms-item>
  77. <uni-forms-item label="手机号" name="phonenumber">
  78. <uni-easyinput v-model="user.phonenumber" placeholder="请输入手机号" />
  79. </uni-forms-item>
  80. <uni-forms-item label="邮箱" name="email">
  81. <uni-easyinput v-model="user.email" placeholder="请输入邮箱" />
  82. </uni-forms-item>
  83. <uni-forms-item label="性别" name="sex" required>
  84. <uni-data-checkbox v-model="user.sex" :localdata="sexs" />
  85. </uni-forms-item>
  86. </uni-forms>
  87. <button type="primary" class="round font30" @click="submit">修改资料</button>
  88. </view> -->
  89. </view>
  90. <u-modal :show="modalShow" :showConfirmButton="true" :showCancelButton="true" @cancel="modalShow = false" @confirm="handleConfirm">
  91. <view class="slot-content" style="width: 100%">
  92. <view class="mb15" style="text-align: center; color: #000; font-weight: 600">{{ modalTitle }}</view>
  93. <view v-if="modalTitle === '修改昵称'">
  94. <u--input v-model="userArr.nickName" :maxlength="5" :placeholder="modalTitle" border="bottom" clearable></u--input>
  95. </view>
  96. <view v-if="modalTitle === '修改手机号'">
  97. <u-input v-model="phone" placeholder="请输入手机号" :maxlength="11" border="bottom" />
  98. <u-input v-model="verify" placeholder="请输入验证码" :maxlength="6" border="bottom">
  99. <template #suffix>
  100. <button class="verify" @click="getVerifyCode">{{ !useStore.codeTime ? "获取验证码" : useStore.codeTime + "s" }}</button>
  101. </template>
  102. </u-input>
  103. </view>
  104. <view v-if="modalTitle === '修改邮箱'">
  105. <u--input v-model="userArr.email" :placeholder="modalTitle" border="bottom" clearable></u--input>
  106. </view>
  107. <view v-if="modalTitle === '修改性别'">
  108. <u-radio-group v-model="userArr.sex" placement="row">
  109. <u-radio v-for="se in sexs" :key="se" :activeColor="proxy.$settingStore.themeColor.color" :label="se.text" :name="se.value" style="margin-right: 15px"></u-radio>
  110. </u-radio-group>
  111. </view>
  112. </view>
  113. </u-modal>
  114. </template>
  115. <script setup>
  116. import config from "@/config";
  117. import storage from "@/utils/storage";
  118. import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
  119. import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
  120. import { useStores, commonStores } from "@/store/modules/index";
  121. import { updateUserProfile, getUserProfile } from "@/api/system/user";
  122. const useStore = useStores();
  123. const { proxy } = getCurrentInstance();
  124. const data = reactive({
  125. tabsList: [{ name: "个人信息" }, { name: "企业/团队" }],
  126. tabsCurrent: 0,
  127. sexs: [
  128. { text: "男", value: "0" },
  129. { text: "女", value: "1" },
  130. ],
  131. modalShow: false,
  132. modalTitle: "",
  133. phone: undefined,
  134. verify: undefined,
  135. });
  136. const { tabsList, tabsCurrent, sexs, modalShow, modalTitle, phone, verify } = toRefs(data);
  137. const { avatar, user, userArr, postGroup, roleGroup } = toRefs(useStore.$state);
  138. function handleUserModal(title) {
  139. modalShow.value = true;
  140. modalTitle.value = title;
  141. }
  142. function handleConfirm() {
  143. if (modalTitle.value == "修改昵称") {
  144. if (!userArr.value.nickName) {
  145. proxy.$modal.showToast("昵称不能为空");
  146. return;
  147. }
  148. updateUserProfile(userArr.value).then((response) => {
  149. proxy.$tab.reLaunch("/pages/mine");
  150. useStore.getUser();
  151. });
  152. }
  153. if (modalTitle.value == "修改手机号") {
  154. useStore.PhoneVerify({
  155. data: {
  156. phone: phone.value,
  157. verify: verify.value,
  158. },
  159. success: (res) => {
  160. userArr.value.phonenumber = phone.value;
  161. updateUserProfile(userArr.value).then((response) => {
  162. proxy.$modal.msgSuccess("修改成功");
  163. proxy.$tab.reLaunch("/pages/mine");
  164. useStore.getUser();
  165. });
  166. },
  167. error: (res) => {
  168. return false;
  169. },
  170. });
  171. }
  172. if (modalTitle.value == "修改邮箱") {
  173. if (!userArr.value.email) {
  174. proxy.$modal.showToast("邮箱不能为空");
  175. return;
  176. }
  177. if (!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(userArr.value.email)) {
  178. proxy.$modal.showToast("请输入正确的邮箱地址");
  179. return;
  180. }
  181. updateUserProfile(userArr.value).then((response) => {
  182. proxy.$tab.reLaunch("/pages/mine");
  183. useStore.getUser();
  184. });
  185. }
  186. if (modalTitle.value == "修改性别") {
  187. if (!userArr.value.sex) {
  188. proxy.$modal.showToast("请选择性别");
  189. return;
  190. }
  191. updateUserProfile(userArr.value).then((response) => {
  192. proxy.$tab.reLaunch("/pages/mine");
  193. useStore.getUser();
  194. });
  195. }
  196. }
  197. /**
  198. * @点击发送验证码
  199. */
  200. function getVerifyCode() {
  201. verify.value = undefined;
  202. useStore.GetCodeImg({
  203. phone: phone.value,
  204. success: (res) => {
  205. proxy.$modal.msgSuccess("发送成功");
  206. },
  207. });
  208. }
  209. /**
  210. * @tabs点击事件
  211. */
  212. function tabsClick(e) {
  213. tabsCurrent.value = e.index;
  214. }
  215. onLoad((options) => {
  216. useStore.getUser();
  217. });
  218. onReady(() => {
  219. // const form = ref(null);
  220. // form.value.setRules(rules.value);
  221. });
  222. onShow(() => {
  223. //调用系统主题颜色
  224. proxy.$settingStore.systemThemeColor([1]);
  225. });
  226. // 自定义导航事件
  227. onNavigationBarButtonTap((e) => {
  228. if (e.float == "right") {
  229. proxy.$tab.navigateTo("/pages/mine/setting/index");
  230. }
  231. });
  232. </script>
  233. <style lang="scss" scoped>
  234. :deep(.uni-page-head__title) {
  235. opacity: 1 !important;
  236. }
  237. .info-container {
  238. .user-section {
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. height: 240px;
  243. padding-top: 44px;
  244. overflow: hidden;
  245. position: relative;
  246. .bg {
  247. position: absolute;
  248. left: 0;
  249. top: 0;
  250. width: 100vw;
  251. opacity: 0.84;
  252. }
  253. .portrait {
  254. position: relative;
  255. width: 104px;
  256. height: 104px;
  257. border-radius: 50%;
  258. border: 3px solid #fff;
  259. }
  260. }
  261. .example {
  262. padding: 15px;
  263. background-color: #fff;
  264. }
  265. .segmented-control {
  266. margin-bottom: 15px;
  267. }
  268. .button-group {
  269. margin-top: 15px;
  270. display: flex;
  271. justify-content: space-around;
  272. }
  273. .form-item {
  274. display: flex;
  275. align-items: center;
  276. flex: 1;
  277. }
  278. .button {
  279. display: flex;
  280. align-items: center;
  281. height: 35px;
  282. line-height: 35px;
  283. margin-left: 10px;
  284. }
  285. }
  286. </style>