myInfo.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view class="ezy-yysz-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">应用设置</text>
  6. </view>
  7. <view class="ezy-tab-border">
  8. <view class="yysz-row-box">
  9. <view class="yysz-item img-item" @click="headClick">
  10. <text>头像</text>
  11. <icon class="yysz-img-box"
  12. :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
  13. </view>
  14. <view class="yysz-item" @click="nichengClick">
  15. <text>昵称</text>
  16. <text>{{myInfoData.nickName}}</text>
  17. </view>
  18. </view>
  19. <view class="yysz-row-box">
  20. <view class="yysz-item" @click="telClick">
  21. <text>手机号码</text>
  22. <text>{{myInfoData.userName}}</text>
  23. </view>
  24. </view>
  25. <view class="yysz-row-box">
  26. <view class="yysz-item" @click="aboutClick">
  27. <text>关于我们</text>
  28. </view>
  29. <view v-if="loginFlag" class="yysz-item" @click="yinsizhengce">
  30. <text>隐私政策</text>
  31. </view>
  32. <view class="yysz-item" @click="kefudianhua">
  33. <text>客服与投诉</text>
  34. <text>4001750778</text>
  35. </view>
  36. <view v-if="loginFlag" class="yysz-item" @click="yonghuzhuxiao">
  37. <icon class="list-icon zhuxiao-icon"></icon>
  38. <text>用户注销</text>
  39. </view>
  40. <view class="yysz-item" @click="exitLogin">
  41. <icon class="list-icon login-out-icon"></icon>
  42. <text>退出登录</text>
  43. </view>
  44. </view>
  45. </view>
  46. <CustomTabBar :currentTabNumber="3">
  47. </CustomTabBar>
  48. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  49. <tip-small-dialog ref="zhuxiaoDialogRef" @confirm-btn="zhuxiaoBtn" :content="zhuxiaoContent"></tip-small-dialog>
  50. <tel-dialog @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  51. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  52. <tip-small-dialog ref="kefuDialogRef" :title="kefuTitle" @confirm-btn="kefuBtn" :content="kefuContent"
  53. class="kefu-dialog"></tip-small-dialog>
  54. <nichengDialog ref="nichengDialogRef" @confirm-btn="nichengBtn" title="修改昵称"></nichengDialog>
  55. </view>
  56. </template>
  57. <script setup>
  58. import agreeContentDialog from '@/pages/login/agreeContentDialog.vue';
  59. import {
  60. toast,
  61. } from "@/utils/common";
  62. import cacheManager from '@/utils/cacheManager.js';
  63. import {
  64. logout
  65. } from '@/api/login.js'
  66. import {
  67. myInfo,
  68. zhuxiao,
  69. duihuanmaCode,
  70. nichengUpdate,
  71. myCardList,
  72. commonCardList,
  73. getFilePolicy,
  74. updataHead
  75. } from '@/api/my.js'
  76. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  77. import {
  78. onLoad,onShow
  79. } from '@dcloudio/uni-app';
  80. import {
  81. reactive,
  82. ref
  83. } from "vue";
  84. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue';
  85. import duihuanmaDialog from '@/components/dialog/duihuanmaDialog.vue';
  86. import nichengDialog from '@/components/dialog/nichengDialog.vue';
  87. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  88. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  89. import telDialog from './components/telDialog.vue'
  90. import { usePermission } from "@/store/permissionStore.js"
  91. const permissionStore = usePermission()
  92. const agreeType = ref(null);
  93. const agreeContentDialogRef = ref(null);
  94. const tipContent = '你确定要执行这个操作吗?';
  95. const zhuxiaoContent = '你确定要执行这个操作吗?';
  96. let loginFlag = ref(false);
  97. let telDialogFlag = ref(false);
  98. let myInfoData = reactive({
  99. userImg: '',
  100. userName: '',
  101. credit: '',
  102. vipFlag: '',
  103. nickName: '',
  104. icon: '',
  105. });
  106. let routerOpt = ref(false);
  107. let appleCode = ref(null);
  108. let currentPlatform = ref(null);
  109. const exitDialogRef = ref(null);
  110. const zhuxiaoDialogRef = ref(null);
  111. const nichengDialogRef = ref(null);
  112. const kefuDialogRef = ref(null);
  113. const kefuTitle = '提示';
  114. const kefuContent = '客服电话:4001750778';
  115. const exitLogin = () => {
  116. exitDialogRef.value.handleShow();
  117. }
  118. function handleBack() {
  119. uni.redirectTo({
  120. url: '/pages/chanpinXuanze/my'
  121. })
  122. }
  123. function headClick() {
  124. chooseImage()
  125. }
  126. const checkAlbumPermission = async () => {
  127. const status = await uni.getSetting()
  128. if (!status.authSetting['scope.album']) {
  129. await uni.authorize({
  130. scope: 'scope.album'
  131. })
  132. }
  133. }
  134. const chooseImage = async () => {
  135. try {
  136. // await checkAlbumPermission()
  137. /* #ifdef APP */
  138. const systemInfo = uni.getSystemInfoSync();
  139. if (systemInfo.platform != 'ios') {
  140. if (!await permissionStore.requstPermission('READ_EXTERNAL_STORAGE')) return
  141. }
  142. /* #endif */
  143. uni.chooseImage({
  144. count: 1,
  145. sizeType: ['compressed'],
  146. sourceType: ['album'], // 仅限相册选择‌:ml-citation{ref="1" data="citationList"}
  147. success: (res) => {
  148. uploadFile(res.tempFilePaths[0])
  149. },
  150. fail: (err) => {
  151. console.error('选择失败:', err)
  152. }
  153. })
  154. } catch (err) {
  155. uni.showModal({
  156. title: '权限申请失败',
  157. content: '请前往设置开启相册权限'
  158. })
  159. }
  160. }
  161. function updateIcon(data) {
  162. updataHead({
  163. icon: data
  164. }).then(res => {
  165. if (res.code == 0) {
  166. uni.showToast({
  167. title: '上传成功',
  168. icon: 'success'
  169. });
  170. } else {
  171. uni.showToast({
  172. title: '上传失败',
  173. });
  174. }
  175. })
  176. }
  177. function uploadFile(filePath) {
  178. const suffix = filePath.split('.').pop();
  179. let req = {
  180. prefix: 'resource/',
  181. suffix: suffix
  182. }
  183. getFilePolicy(req).then(res => {
  184. if (res.code === 0) {
  185. const policyData = res.data;
  186. console.log('policyData', policyData);
  187. uni.uploadFile({
  188. url: policyData.uploadUrl,
  189. filePath: filePath,
  190. name: 'file',
  191. formData: {
  192. key: policyData.key,
  193. policy: policyData.policy,
  194. OSSAccessKeyId: policyData.accessid,
  195. signature: policyData.signature,
  196. success_action_status: '200'
  197. },
  198. header: {
  199. 'Content-Type': 'multipart/form-data'
  200. },
  201. success(uploadRes) {
  202. console.log('uploadRes', uploadRes);
  203. if (uploadRes.statusCode === 200) {
  204. myInfoData.icon = `${policyData.downloadUrl}/${policyData.key}`;
  205. updateIcon(myInfoData.icon)
  206. } else {
  207. uni.showToast({
  208. title: '阿里云上传错误,请重试!',
  209. });
  210. return false
  211. }
  212. },
  213. fail(err) {
  214. console.log('err', err);
  215. }
  216. });
  217. }
  218. })
  219. }
  220. function nichengClick() {
  221. nichengDialogRef.value.handleShow();
  222. }
  223. // 退出按钮
  224. const exitBtn = () => {
  225. if (loginFlag.value) {
  226. logout().then(res => {
  227. toast('退出登录成功')
  228. cacheManager.clearAll();
  229. uni.reLaunch({
  230. url: '/pages/login/index'
  231. });
  232. }).catch(err => {
  233. toast('退出登录失败,请稍后重试')
  234. })
  235. } else {
  236. uni.reLaunch({
  237. url: '/pages/login/index'
  238. });
  239. }
  240. }
  241. const zhuxiaoBtn = () => {
  242. let req = {
  243. }
  244. zhuxiao().then(res => {
  245. cacheManager.clearAll();
  246. toast('用户注销成功')
  247. uni.redirectTo({
  248. url: '/pages/login/index'
  249. });
  250. }).catch(err => {
  251. toast('失败,请稍后重试')
  252. })
  253. }
  254. function yonghuzhuxiao() {
  255. zhuxiaoDialogRef.value.handleShow();
  256. }
  257. function nichengBtn(data) {
  258. console.log('data', data);
  259. let req = {
  260. nickName: data
  261. }
  262. nichengUpdate(req).then(res => {
  263. if (res.code == 0) {
  264. toast('修改成功')
  265. myInfoData.nickName = data
  266. } else {
  267. toast('修改失败请重试或联系管理员')
  268. return false
  269. }
  270. }).catch(err => {
  271. })
  272. }
  273. function yinsizhengce() {
  274. agreeType.value = 'ystk'
  275. agreeContentDialogRef.value.handleShow();
  276. }
  277. function kefudianhua() {
  278. kefuDialogRef.value.handleShow();
  279. }
  280. function kefuBtn() {
  281. kefuDialogRef.value.handleClose();
  282. }
  283. // 手机号码
  284. function telClick() {
  285. if (loginFlag.value) {
  286. telDialogFlag.value = true;
  287. } else {
  288. youkeDialogRef.value.handleShow();
  289. }
  290. }
  291. // 手机号码绑定
  292. function bindBtn() {
  293. telDialogFlag.value = false;
  294. myGetAuth()
  295. }
  296. // 关闭手机号码弹窗
  297. function telClose() {
  298. telDialogFlag.value = false;
  299. }
  300. // 关于我们
  301. function aboutClick() {
  302. uni.redirectTo({
  303. url: '/pages/chanpinXuanze/aboutPage'
  304. });
  305. }
  306. // 获取用户数据
  307. function getMyInfo() {
  308. myInfo({}).then(res => {
  309. myInfoData.userName = res.data.userName;
  310. myInfoData.credit = res.data.credit;
  311. myInfoData.nickName = res.data.nickName;
  312. if (res.data.nickName) {
  313. myInfoData.nickName = res.data.nickName;
  314. } else {
  315. myInfoData.nickName = '鹅状元';
  316. }
  317. if (res.data.icon) {
  318. myInfoData.icon = res.data.icon;
  319. } else {
  320. getUserImg(res.data.growthType)
  321. }
  322. })
  323. }
  324. function getUserImg(data) {
  325. switch (data) {
  326. case 0:
  327. myInfoData.icon = 'static/images/my/head-img0.png'
  328. break;
  329. case 1:
  330. myInfoData.icon = 'static/images/my/head-img1.png'
  331. break;
  332. case 2:
  333. myInfoData.icon = 'static/images/my/head-img2.png'
  334. break;
  335. case 3:
  336. myInfoData.icon = 'static/images/my/head-img3.png'
  337. break;
  338. default:
  339. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  340. break;
  341. }
  342. }
  343. onLoad((options) => {
  344. loginFlag.value = true;
  345. getMyInfo();
  346. })
  347. </script>