setting.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="mobile-setting-page">
  3. <view class="setting-list-box">
  4. <view class="list-row no-jt-row img-list-row">
  5. <text>头像</text>
  6. <img class="head-img" :src="settingData.icon" v-if="settingData.icon">
  7. <icon class="phone-default-userImg setting-default-userImg" v-else></icon>
  8. </view>
  9. <view class="list-row no-jt-row">
  10. <text>用户名</text>
  11. <text class="row-content">{{settingData.userName}}</text>
  12. </view>
  13. <!-- <view class="list-row" @click="goToPage('realName')">
  14. <text>真实姓名</text>
  15. <text class="row-content">{{settingData.realName}}</text>
  16. </view>
  17. <view class="list-row" @click="goToPage('gender')">
  18. <text>性别</text>
  19. <text class="row-content" v-if="settingData.gender===0"></text>
  20. <text class="row-content" v-if="settingData.gender===1">男</text>
  21. <text class="row-content" v-if="settingData.gender===2">女</text>
  22. </view>
  23. <view class="list-row" @click="goToPage('shengri')">
  24. <text>生日</text>
  25. <text class="row-content">{{settingData.birthday}}</text>
  26. </view>
  27. <view class="list-row" @click="goToPage('tel')">
  28. <text>电话</text>
  29. <text class="row-content">{{settingData.tel}}</text>
  30. </view>
  31. <view class="list-row" @click="goToPage('xgmm')">
  32. <text>修改密码</text>
  33. <text class="row-content">{{settingData.xgmm}}</text>
  34. </view> -->
  35. <view class="list-row no-jt-row" @click="goToPage('qlhc')">
  36. <text>清理缓存</text>
  37. <text class="row-content"></text>
  38. </view>
  39. </view>
  40. <view @click="quitClick" class="exit-login-btn">退出登录</view>
  41. <real-name-dialog ref="realNameDialogRef" @confirm-btn="realNameBtn"></real-name-dialog>
  42. <tel-dialog ref="telDialogRef" @confirm-btn="telBtn"></tel-dialog>
  43. <password-dialog ref="passwordDialogRef" @confirm-btn="passwordBtn"></password-dialog>
  44. <birthday-dialog ref="birthdayDialogRef" @confirm-btn="birthdayBtn"></birthday-dialog>
  45. <gender-dialog ref="genderDialogRef" @confirm-btn="genderBtn"></gender-dialog>
  46. </view>
  47. </template>
  48. <script setup>
  49. import {reactive,ref} from "vue";
  50. import {logout} from '@/api/login.js'
  51. import {toast} from "@/utils/common";
  52. import {onLoad} from '@dcloudio/uni-app';
  53. import {getUserInfo,getUserUpRealName,getUserUpTel,getUserUpPassword,getUserUpBirthday,getUserUpGender} from '@/api/my.js'
  54. import {useUserCache} from "@/utils/userCache.js"
  55. import cacheManager from '@/utils/cacheManager.js';
  56. import realNameDialog from './components/realNameDialog.vue';
  57. import telDialog from './components/telDialog.vue';
  58. import passwordDialog from './components/passwordDialog.vue';
  59. import birthdayDialog from './components/birthdayDialog.vue';
  60. import genderDialog from './components/genderDialog.vue';
  61. let settingData = reactive({
  62. icon: '',
  63. userName: '',
  64. realName: '',
  65. gender:'',
  66. birthday: '',
  67. tel:'',
  68. });
  69. onLoad(() => {
  70. getSettingInit()
  71. })
  72. function getSettingInit(){
  73. getUserInfo({}).then(res => {
  74. settingData.icon = res.data.icon;
  75. settingData.userName = res.data.userName;
  76. settingData.realName = res.data.realName;
  77. settingData.gender = res.data.gender;
  78. settingData.birthday = res.data.birthday;
  79. settingData.tel = res.data.tel;
  80. })
  81. }
  82. /***** 跳转 *****/
  83. function goToPage(data){
  84. switch (data) {
  85. case 'realName':
  86. realNameDialogRef.value.handleShow();
  87. break;
  88. case 'gender':
  89. genderDialogRef.value.handleShow();
  90. break;
  91. case 'shengri':
  92. birthdayDialogRef.value.handleShow();
  93. break;
  94. case 'tel':
  95. telDialogRef.value.handleShow();
  96. break;
  97. case 'xgmm':
  98. passwordDialogRef.value.handleShow();
  99. break;
  100. case 'qlhc':
  101. clearLocation()
  102. break;
  103. }
  104. }
  105. function clearLocation(){
  106. // 清理考试缓存
  107. useUserCache().removeCache('kaoshiCache');
  108. }
  109. function quitClick(){
  110. uni.showModal({
  111. title: '提示',
  112. content: '你确定要执行这个操作吗?',
  113. success: (res) => {
  114. if (res.confirm) {
  115. // 确定
  116. quit()
  117. } else if (res.cancel) {
  118. // 取消
  119. }
  120. }
  121. });
  122. }
  123. function quit (){
  124. logout().then(res=>{
  125. toast('退出登录成功')
  126. uni.navigateTo({
  127. url: '/pages/login'
  128. });
  129. cacheManager.clearAll();
  130. }).catch(err => {
  131. toast('退出登录失败,请稍后重试')
  132. })
  133. }
  134. /***** 真实姓名 *****/
  135. const realNameDialogRef = ref(null);
  136. function realNameBtn(data){
  137. console.log(data,'data');
  138. settingData.realName = data;
  139. const opt = {
  140. realName: settingData.realName,
  141. }
  142. getUserUpRealName(opt).then(res => {
  143. if (res.data) {
  144. uni.showToast({
  145. title: '更新成功'
  146. })
  147. realNameDialogRef.value.handleClose();
  148. }
  149. })
  150. }
  151. /***** 电话 *****/
  152. const telDialogRef = ref(null);
  153. function telBtn(data){
  154. console.log(data,'data');
  155. settingData.tel = data;
  156. const opt = {
  157. tel: settingData.tel,
  158. }
  159. getUserUpTel(opt).then(res => {
  160. if (res.data) {
  161. uni.showToast({
  162. title: '更新成功'
  163. })
  164. telDialogRef.value.handleClose();
  165. }
  166. })
  167. }
  168. /***** 修改日期 *****/
  169. const birthdayDialogRef = ref(null);
  170. function birthdayBtn(data){
  171. settingData.birthday = data;
  172. const opt = {
  173. brithday: settingData.birthday,
  174. }
  175. getUserUpBirthday(opt).then(res => {
  176. if (res.data) {
  177. uni.showToast({
  178. title: '更新成功'
  179. })
  180. birthdayDialogRef.value.handleClose();
  181. }
  182. })
  183. }
  184. /***** 修改性别 *****/
  185. const genderDialogRef = ref(null);
  186. function genderBtn(data){
  187. settingData.gender = data;
  188. const opt = {
  189. gender: data,
  190. }
  191. getUserUpGender(opt).then(res => {
  192. if (res.data) {
  193. uni.showToast({
  194. title: '更新成功'
  195. })
  196. birthdayDialogRef.value.handleClose();
  197. }
  198. })
  199. }
  200. /***** 修改密码 *****/
  201. const passwordDialogRef = ref(null);
  202. function passwordBtn(data){
  203. const opt = {
  204. passwordOld: data.oldPassWord,
  205. passwordNew: data.newPassWord,
  206. }
  207. getUserUpdatePassword(opt).then(res => {
  208. if (res.data) {
  209. uni.showToast({
  210. title: '更新成功'
  211. })
  212. passwordDialogRef.value.handleClose();
  213. }
  214. })
  215. }
  216. </script>
  217. <style>
  218. </style>