index.vue 11 KB

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