yingyongshezhi.vue 9.8 KB

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