myInfo.vue 8.3 KB

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