yingyongshezhi.vue 9.6 KB

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