myInfo.vue 8.9 KB

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