yingyongshezhi.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. const agreeType = ref(null);
  97. const agreeContentDialogRef = ref(null);
  98. const tipContent = '你确定要执行这个操作吗?';
  99. const zhuxiaoContent = '你确定要执行这个操作吗?';
  100. let loginFlag = ref(false);
  101. let telDialogFlag = ref(false);
  102. let myInfoData = reactive({
  103. userImg: '',
  104. userName: '',
  105. credit: '',
  106. vipFlag: '',
  107. nickName: '',
  108. icon: '',
  109. });
  110. let routerOpt = ref(false);
  111. let appleCode = ref(null);
  112. let currentPlatform = ref(null);
  113. const exitDialogRef = ref(null);
  114. const zhuxiaoDialogRef = ref(null);
  115. const nichengDialogRef = ref(null);
  116. const kefuDialogRef = ref(null);
  117. const kefuTitle = '提示';
  118. const kefuContent = '客服电话:4001750778';
  119. const exitLogin = () => {
  120. exitDialogRef.value.handleShow();
  121. }
  122. function handleBack() {
  123. uni.redirectTo({
  124. url: '/pages/my/index'
  125. })
  126. }
  127. function headClick() {
  128. chooseImage()
  129. }
  130. const checkAlbumPermission = async () => {
  131. const status = await uni.getSetting()
  132. if (!status.authSetting['scope.album']) {
  133. await uni.authorize({
  134. scope: 'scope.album'
  135. })
  136. }
  137. }
  138. const chooseImage = async () => {
  139. try {
  140. // await checkAlbumPermission()
  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. if (loginFlag.value) {
  301. uni.redirectTo({
  302. url: '/pages/my/aboutPage'
  303. });
  304. } else {
  305. uni.redirectTo({
  306. url: `/pages/my/aboutPage?levelId=${routerOpt.levelId}&typeId=${routerOpt.typeId}&subjectId=${routerOpt.subjectId}&tipFlag=${routerOpt.tipFlag}`
  307. });
  308. }
  309. }
  310. // 获取用户数据
  311. function getMyInfo() {
  312. myInfo({}).then(res => {
  313. myInfoData.userName = res.data.userName;
  314. myInfoData.credit = res.data.credit;
  315. myInfoData.nickName = res.data.nickName;
  316. if (res.data.nickName) {
  317. myInfoData.nickName = res.data.nickName;
  318. } else {
  319. myInfoData.nickName = '鹅状元';
  320. }
  321. if (res.data.icon) {
  322. myInfoData.icon = res.data.icon;
  323. } else {
  324. getUserImg(res.data.growthType)
  325. }
  326. })
  327. }
  328. function getUserImg(data) {
  329. switch (data) {
  330. case 0:
  331. myInfoData.icon = 'static/images/my/head-img0.png'
  332. break;
  333. case 1:
  334. myInfoData.icon = 'static/images/my/head-img1.png'
  335. break;
  336. case 2:
  337. myInfoData.icon = 'static/images/my/head-img2.png'
  338. break;
  339. case 3:
  340. myInfoData.icon = 'static/images/my/head-img3.png'
  341. break;
  342. default:
  343. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  344. break;
  345. }
  346. }
  347. function isIOSorAndroid() {
  348. const systemInfo = uni.getSystemInfoSync();
  349. console.log('systemInfo', systemInfo);
  350. if (systemInfo.platform == 'ios') {
  351. return currentPlatform.value = 'ios'
  352. } else {
  353. return currentPlatform.value = 'android'
  354. }
  355. }
  356. onLoad((options) => {
  357. isIOSorAndroid()
  358. loginFlag.value = true;
  359. getMyInfo();
  360. })
  361. </script>