yingyongshezhi.vue 9.4 KB

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