myInfo.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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"> </CustomTabBar> -->
  45. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  46. <tip-small-dialog ref="zhuxiaoDialogRef" @confirm-btn="zhuxiaoBtn" :content="zhuxiaoContent"></tip-small-dialog>
  47. <tel-dialog @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  48. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  49. <tip-small-dialog ref="kefuDialogRef" :title="kefuTitle" @confirm-btn="kefuBtn" :content="kefuContent"
  50. class="kefu-dialog"></tip-small-dialog>
  51. <nichengDialog ref="nichengDialogRef" @confirm-btn="nichengBtn" title="修改昵称"></nichengDialog>
  52. </view>
  53. </template>
  54. <script setup>
  55. import agreeContentDialog from '@/pages/login/agreeContentDialog.vue';
  56. import {
  57. toast,
  58. } from "@/utils/common";
  59. import cacheManager from '@/utils/cacheManager.js';
  60. import {
  61. logout
  62. } from '@/api/login.js'
  63. import {
  64. myInfo,
  65. zhuxiao,
  66. duihuanmaCode,
  67. nichengUpdate,
  68. myCardList,
  69. commonCardList,
  70. getFilePolicy,
  71. updataHead
  72. } from '@/api/my.js'
  73. // import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  74. import {
  75. onLoad,onShow
  76. } from '@dcloudio/uni-app';
  77. import {
  78. reactive,
  79. ref
  80. } from "vue";
  81. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue';
  82. import duihuanmaDialog from '@/components/dialog/duihuanmaDialog.vue';
  83. import nichengDialog from '@/components/dialog/nichengDialog.vue';
  84. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  85. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  86. import telDialog from './components/telDialog.vue'
  87. import { usePermission } from "@/store/permissionStore.js"
  88. const permissionStore = usePermission()
  89. const agreeType = ref(null);
  90. const agreeContentDialogRef = ref(null);
  91. const tipContent = '你确定要执行这个操作吗?';
  92. const zhuxiaoContent = '你确定要执行这个操作吗?';
  93. let loginFlag = ref(false);
  94. let telDialogFlag = ref(false);
  95. let myInfoData = reactive({
  96. userImg: '',
  97. userName: '',
  98. credit: '',
  99. vipFlag: '',
  100. nickName: '',
  101. icon: '',
  102. });
  103. let routerOpt = ref(false);
  104. let appleCode = ref(null);
  105. let currentPlatform = ref(null);
  106. const exitDialogRef = ref(null);
  107. const zhuxiaoDialogRef = ref(null);
  108. const nichengDialogRef = ref(null);
  109. const kefuDialogRef = ref(null);
  110. const kefuTitle = '提示';
  111. const kefuContent = '客服电话:4001750778';
  112. const exitLogin = () => {
  113. exitDialogRef.value.handleShow();
  114. }
  115. function handleBack() {
  116. uni.switchTab({
  117. url: '/pages/chanpinMy/my'
  118. })
  119. }
  120. function headClick() {
  121. chooseImage()
  122. }
  123. const checkAlbumPermission = async () => {
  124. const status = await uni.getSetting()
  125. if (!status.authSetting['scope.album']) {
  126. await uni.authorize({
  127. scope: 'scope.album'
  128. })
  129. }
  130. }
  131. const chooseImage = async () => {
  132. try {
  133. // await checkAlbumPermission()
  134. /* #ifdef APP */
  135. const systemInfo = uni.getSystemInfoSync();
  136. if (systemInfo.platform != 'ios') {
  137. if (!await permissionStore.requstPermission('READ_EXTERNAL_STORAGE')) return
  138. }
  139. /* #endif */
  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. uni.navigateTo({
  272. url: '/pages/chanpinMy/yinsizhengce'
  273. });
  274. // agreeType.value = 'ystk'
  275. // agreeContentDialogRef.value.handleShow();
  276. }
  277. function kefudianhua() {
  278. kefuDialogRef.value.handleShow();
  279. }
  280. function kefuBtn() {
  281. kefuDialogRef.value.handleClose();
  282. }
  283. // 手机号码
  284. function telClick() {
  285. if (loginFlag.value) {
  286. telDialogFlag.value = true;
  287. } else {
  288. youkeDialogRef.value.handleShow();
  289. }
  290. }
  291. // 手机号码绑定
  292. function bindBtn() {
  293. telDialogFlag.value = false;
  294. myGetAuth()
  295. }
  296. // 关闭手机号码弹窗
  297. function telClose() {
  298. telDialogFlag.value = false;
  299. }
  300. // 关于我们
  301. function aboutClick() {
  302. uni.navigateTo({
  303. url: '/pages/chanpinMy/aboutPage'
  304. });
  305. }
  306. // 获取用户数据
  307. function getMyInfo() {
  308. myInfo({}).then(res => {
  309. myInfoData.userName = res.data.userName;
  310. myInfoData.credit = res.data.credit;
  311. myInfoData.nickName = res.data.nickName;
  312. if (res.data.nickName) {
  313. myInfoData.nickName = res.data.nickName;
  314. } else {
  315. myInfoData.nickName = '鹅状元';
  316. }
  317. if (res.data.icon) {
  318. myInfoData.icon = res.data.icon;
  319. } else {
  320. getUserImg(res.data.growthType)
  321. }
  322. })
  323. }
  324. function getUserImg(data) {
  325. switch (data) {
  326. case 0:
  327. myInfoData.icon = 'static/images/my/head-img0.png'
  328. break;
  329. case 1:
  330. myInfoData.icon = 'static/images/my/head-img1.png'
  331. break;
  332. case 2:
  333. myInfoData.icon = 'static/images/my/head-img2.png'
  334. break;
  335. case 3:
  336. myInfoData.icon = 'static/images/my/head-img3.png'
  337. break;
  338. default:
  339. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  340. break;
  341. }
  342. }
  343. onLoad((options) => {
  344. loginFlag.value = true;
  345. getMyInfo();
  346. })
  347. </script>