setting.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. </view>
  45. </template>
  46. <script setup>
  47. import {reactive,ref} from "vue";
  48. import {logout} from '@/api/login.js'
  49. import {toast} from "@/utils/common";
  50. import {onLoad} from '@dcloudio/uni-app';
  51. import {getUserInfo,getUserUpRealName,getUserUpTel,getUserUpPassword,getUserUpBirthday,getUserUpGender} from '@/api/my.js'
  52. import {useUserCache} from "@/utils/userCache.js"
  53. import cacheManager from '@/utils/cacheManager.js';
  54. import realNameDialog from './components/realNameDialog.vue';
  55. import telDialog from './components/telDialog.vue';
  56. import passwordDialog from './components/passwordDialog.vue';
  57. let settingData = reactive({
  58. icon: '',
  59. userName: '',
  60. realName: '',
  61. gender:'',
  62. birthday: '',
  63. tel:'',
  64. });
  65. onLoad(() => {
  66. getSettingInit()
  67. })
  68. function getSettingInit(){
  69. getUserInfo({}).then(res => {
  70. settingData.icon = res.data.icon;
  71. settingData.userName = res.data.userName;
  72. settingData.realName = res.data.realName;
  73. settingData.gender = res.data.gender;
  74. settingData.birthday = res.data.birthday;
  75. settingData.tel = res.data.tel;
  76. })
  77. }
  78. /***** 跳转 *****/
  79. function goToPage(data){
  80. switch (data) {
  81. case 'realName':
  82. realNameDialogRef.value.handleShow();
  83. break;
  84. case 'gender':
  85. genderDialogRef.value.handleShow();
  86. break;
  87. case 'shengri':
  88. birthdayDialogRef.value.handleShow();
  89. break;
  90. case 'tel':
  91. telDialogRef.value.handleShow();
  92. break;
  93. case 'xgmm':
  94. passwordDialogRef.value.handleShow();
  95. break;
  96. case 'qlhc':
  97. clearLocation()
  98. break;
  99. }
  100. }
  101. function clearLocation(){
  102. // 清理考试缓存
  103. useUserCache().removeCache('kaoshiCache');
  104. }
  105. function quitClick(){
  106. uni.showModal({
  107. title: '提示',
  108. content: '你确定要执行这个操作吗?',
  109. success: (res) => {
  110. if (res.confirm) {
  111. // 确定
  112. quit()
  113. } else if (res.cancel) {
  114. // 取消
  115. }
  116. }
  117. });
  118. }
  119. function quit (){
  120. logout().then(res=>{
  121. toast('退出登录成功')
  122. uni.navigateTo({
  123. url: '/pages/login'
  124. });
  125. cacheManager.clearAll();
  126. }).catch(err => {
  127. toast('退出登录失败,请稍后重试')
  128. })
  129. }
  130. /***** 真实姓名 *****/
  131. const realNameDialogRef = ref(null);
  132. function realNameBtn(data){
  133. console.log(data,'data');
  134. settingData.realName = data;
  135. const opt = {
  136. realName: settingData.realName,
  137. }
  138. getUserUpRealName(opt).then(res => {
  139. if (res.data) {
  140. uni.showToast({
  141. title: '更新成功'
  142. })
  143. realNameDialogRef.value.handleClose();
  144. }
  145. })
  146. }
  147. /***** 电话 *****/
  148. const telDialogRef = ref(null);
  149. function telBtn(data){
  150. console.log(data,'data');
  151. settingData.tel = data;
  152. const opt = {
  153. tel: settingData.tel,
  154. }
  155. getUserUpTel(opt).then(res => {
  156. if (res.data) {
  157. uni.showToast({
  158. title: '更新成功'
  159. })
  160. telDialogRef.value.handleClose();
  161. }
  162. })
  163. }
  164. /***** 修改日期 *****/
  165. const birthdayDialogRef = ref(null);
  166. function birthdayBtn(data){
  167. settingData.birthday = data;
  168. const opt = {
  169. brithday: settingData.birthday,
  170. }
  171. getUserUpBirthday(opt).then(res => {
  172. if (res.data) {
  173. uni.showToast({
  174. title: '更新成功'
  175. })
  176. birthdayDialogRef.value.handleClose();
  177. }
  178. })
  179. }
  180. /***** 修改性别 *****/
  181. const genderDialogRef = ref(null);
  182. function genderBtn(data){
  183. settingData.gender = data;
  184. const opt = {
  185. gender: data,
  186. }
  187. getUserUpGender(opt).then(res => {
  188. if (res.data) {
  189. uni.showToast({
  190. title: '更新成功'
  191. })
  192. birthdayDialogRef.value.handleClose();
  193. }
  194. })
  195. }
  196. /***** 修改密码 *****/
  197. const passwordDialogRef = ref(null);
  198. function passwordBtn(data){
  199. const opt = {
  200. passwordOld: data.oldPassWord,
  201. passwordNew: data.newPassWord,
  202. }
  203. getUserUpdatePassword(opt).then(res => {
  204. if (res.data) {
  205. uni.showToast({
  206. title: '更新成功'
  207. })
  208. passwordDialogRef.value.handleClose();
  209. }
  210. })
  211. }
  212. </script>
  213. <style>
  214. </style>