set.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <view :class="[AppTheme]" class="container">
  3. <view class="top">
  4. <view class="list-cell b-b m-t" @click="upload" hover-class="cell-hover" :hover-stay-time="50">
  5. <text class="cell-tit">头像:</text>
  6. <view class="upload-img left" v-if="!touPic">
  7. <image class="portrait" :src="siteinfo.root_img+'/static/app/imgs/mine/upload.png'" mode=""></image>
  8. </view>
  9. <view class="icon" v-if="touPic">
  10. <image class="portrait" :src="touPic" mode=""></image>
  11. </view>
  12. <text class="cell-more yticon icon-you"></text>
  13. </view>
  14. <view class="list-cell m-t b-b" @click="goCname" hover-class="cell-hover" :hover-stay-time="50">
  15. <text class="cell-tit">昵称:</text>
  16. <text class="left">{{ userInfo.nickname ? userInfo.nickname : name }}</text>
  17. <u-icon name="arrow-right"></u-icon>
  18. </view>
  19. <view class="list-cell m-t b-b" @click="gorenzheng" hover-class="cell-hover" :hover-stay-time="50">
  20. <text class="cell-tit">实名认证:</text>
  21. <text class="left">{{ auth }}</text>
  22. <u-icon name="arrow-right"></u-icon>
  23. </view>
  24. </view>
  25. <view class="bottom">
  26. <!-- <view class="list-cell b-b" @click="goZfb" hover-class="cell-hover" :hover-stay-time="50">
  27. <text class="cell-tit">绑定支付宝:</text>
  28. <text class="left">{{zfb}}</text>
  29. <text class="cell-more yticon icon-you"></text>
  30. </view> -->
  31. <!-- #ifdef APP-PLUS -->
  32. <view @click="bindwexin(3)" class="list-cell b-b" hover-class="cell-hover" :hover-stay-time="50">
  33. <text class="cell-tit">绑定微信:</text>
  34. <text
  35. class="left">{{ userInfo.openid == '' ? '未授权' : '已授权' || wxUserInfo.openid ? '已授权' : '未授权' }}</text>
  36. <u-icon name="arrow-right"></u-icon>
  37. </view>
  38. <!-- #endif -->
  39. <!-- #ifdef H5 -->
  40. <view @click="getCode()" class="list-cell b-b" hover-class="cell-hover" :hover-stay-time="50">
  41. <text class="cell-tit">绑定微信:</text>
  42. <text
  43. class="left">{{ userInfo.openid == '' ? '未授权' : '已授权' || wxUserInfo.openid ? '已授权' : '未授权' }}</text>
  44. <u-icon name="arrow-right"></u-icon>
  45. </view>
  46. <!-- #endif -->
  47. <view class="list-cell b-b" @click="goChangemima" hover-class="cell-hover" :hover-stay-time="50">
  48. <text class="cell-tit">支付密码:</text>
  49. <text class="left">{{ mima }}</text>
  50. <u-icon name="arrow-right"></u-icon>
  51. </view>
  52. <view class="list-cell b-b" @click="navTo" hover-class="cell-hover" :hover-stay-time="50">
  53. <text class="cell-tit">收货地址:</text>
  54. <text class="left">{{ dizhi }}</text>
  55. <u-icon name="arrow-right"></u-icon>
  56. </view>
  57. <!-- #ifdef APP-PLUS -->
  58. <view class="list-cell b-b" hover-class="cell-hover" :hover-stay-time="50" @click="checknew">
  59. <text class="cell-tit">系统版本:</text>
  60. <text class="left">{{ version }}</text>
  61. <u-icon name="arrow-right"></u-icon>
  62. </view>
  63. <!-- #endif -->
  64. <view class="list-cell log-out-btn " @click="toLogout"><text class="cell-tit bg-linear-gradient">退出登录</text>
  65. </view>
  66. </view>
  67. <!-- #ifdef APP-PLUS -->
  68. <updatepage class='updatepage' ref="vupdate" :isUpdate="isUpdate"></updatepage>
  69. <!-- #endif -->
  70. </view>
  71. </template>
  72. <script>
  73. import mineApi from '@/api/mine/index.js';
  74. import update from "@/api/update/index.js"
  75. import {
  76. getSign
  77. } from '../../../api/appsecret.js';
  78. import {
  79. pathToBase64
  80. } from "@/js/pathto64.js"
  81. import {
  82. mapMutations
  83. } from 'vuex';
  84. export default {
  85. data() {
  86. return {
  87. primary: this.$theme.primary,
  88. version: "0.0.0",
  89. flag: false,
  90. name: '去设置',
  91. touPic: '',
  92. fileList: [],
  93. userInfo: {},
  94. zfb: '去绑定',
  95. mima: '去设置',
  96. dizhi: '去添加',
  97. wxUserInfo: {},
  98. auth: '',
  99. siteinfo: getApp().globalData.siteinfo,
  100. headimg: '',
  101. isUpdate: false,
  102. appid: ''
  103. };
  104. },
  105. onLoad(options) {
  106. let that = this;
  107. let config = that.$init_config(1, function(res) {
  108. if (res && res.app) {
  109. that.appid = res.app.wxgzhappid;
  110. }
  111. });
  112. // #ifdef APP
  113. that.getVersionAndPlatform() //检测当前版本号
  114. // #endif
  115. that.wxUserInfo = uni.getStorageSync('wxUserInfo');
  116. mineApi.vipIndex().then(ret => {
  117. if (ret.status == 200) {
  118. that.touPic = ret.data.vip.headimgurl;
  119. that.userInfo = ret.data.data;
  120. if (ret.data.data.is_auth == 0) {
  121. that.renzhengcode = "未认证"
  122. } else if (ret.data.data.is_auth == 1) {
  123. that.renzhengcode = "审核中"
  124. } else if (ret.data.data.is_auth == 2) {
  125. that.renzhengcode = "已通过"
  126. } else {
  127. that.renzhengcode = "已驳回"
  128. }
  129. if (ret.data.data.pay_password) {
  130. that.mima = "已设置"
  131. }
  132. if (ret.data.hasaddr == 1) {
  133. that.dizhi = '已添加';
  134. }
  135. if (ret.data.data.is_auth == 0) {
  136. that.auth = '未认证';
  137. }
  138. if (ret.data.data.is_auth == 1) {
  139. that.auth = '审核中';
  140. }
  141. if (ret.data.data.is_auth == 2) {
  142. that.auth = '已认证';
  143. }
  144. }
  145. });
  146. },
  147. methods: {
  148. checknew() {
  149. this.$refs.vupdate.upgrade();
  150. },
  151. getCode() {
  152. let redirect = encodeURIComponent(window.location.href); //重定向回来的地址
  153. let wx_code = this.getUrlParam("code"); // 截取url中的code
  154. //判断有没有code
  155. if (!wx_code) {
  156. //获取code的地址。获取成功重定向后地址栏中将会带有code,判断没有code的话,就跳转到微信官方链接上获取,获取成功后会再重定向回来,注意url是需要使用encodeURIComponent处理一下编码的
  157. window.location.href =
  158. `https://open.weixin.qq.com/connect/oauth2/authorizeappid=${this.appid}&redirect_uri=${redirect}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`;
  159. } else {
  160. // 获取到了code
  161. this.getOpenId(wx_code); //把code传给后台获取用户信息
  162. }
  163. },
  164. getUrlParam: function(name) {
  165. let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  166. let r = window.location.search.substr(1).match(reg);
  167. if (r != null) return unescape(r[2]);
  168. return null;
  169. },
  170. getOpenId(code) {
  171. mineApi.bindwx({
  172. type: 2,
  173. code: code
  174. })
  175. },
  176. bindwexin(index) { //绑定微信
  177. let that = this
  178. if (index == 3) {
  179. uni.login({
  180. provider: 'weixin',
  181. // onlyAuthorize: true,
  182. success: function(loginRes) {
  183. uni.getUserInfo({
  184. provider: 'weixin',
  185. success: function(userinfoRes) {
  186. let formdata = {
  187. type: index,
  188. openid: userinfoRes.userInfo.openId,
  189. nickname: userinfoRes.userInfo.nickName,
  190. sex: userinfoRes.userInfo.gender,
  191. headimgurl: userinfoRes.userInfo.avatarUrl,
  192. }
  193. mineApi.bindwx(formdata)
  194. .then(res => {
  195. console.log(res)
  196. if (res.code === 1) {
  197. uni.showToast({
  198. title: res.msg,
  199. icon: "none"
  200. })
  201. that.weixinbind = true
  202. that.editsuccess()
  203. } else {
  204. uni.showToast({
  205. title: res.msg,
  206. icon: "none"
  207. })
  208. that.weixinbind = false
  209. }
  210. })
  211. },
  212. fail: function() {
  213. uni.showToast({
  214. title: res.msg,
  215. icon: "none"
  216. })
  217. }
  218. })
  219. },
  220. fail: function() {
  221. uni.showToast({
  222. icon: 'none',
  223. title: '登陆失败'
  224. })
  225. }
  226. })
  227. } else if (index == 2) {}
  228. },
  229. image(imgurl) { //imgurl 本地图片路径
  230. let that = this
  231. var img = imgurl;
  232. function getBase64Image(img) {
  233. var canvas = document.createElement("canvas");
  234. canvas.width = img.width;
  235. canvas.height = img.height;
  236. var ctx = canvas.getContext("2d");
  237. ctx.drawImage(img, 0, 0, img.width, img.height);
  238. var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
  239. var dataURL = canvas.toDataURL("image/" + ext);
  240. return dataURL;
  241. }
  242. var image = new Image();
  243. image.src = img;
  244. image.onload = function() {
  245. var base64 = getBase64Image(image); //转换之后的图片路径
  246. that.headimg = base64
  247. console.log(that.headimg, "base640000000")
  248. }
  249. },
  250. upload() {
  251. let that = this;
  252. // #ifdef MP-WEIXIN
  253. uni.chooseImage({
  254. count: 1, //默认9
  255. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  256. success: function(res) {
  257. uni.getFileSystemManager().readFile({
  258. filePath: res.tempFilePaths[0], //选择图片返回的相对路径
  259. encoding: 'base64', //编码格式
  260. success: v => {
  261. //成功的回调
  262. let base64 = 'data:image/jpeg;base64,' + v.data;
  263. mineApi.addheadimg({
  264. pic: base64
  265. })
  266. .then(res => {
  267. if (res.status == 200) {
  268. that.touPic = res.data;
  269. }
  270. });
  271. }
  272. });
  273. }
  274. });
  275. // #endif
  276. // #ifdef H5 || APP-PLUS
  277. uni.chooseImage({
  278. count: 1, //默认9
  279. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  280. success: function(res) {
  281. pathToBase64(res.tempFilePaths[0]).then(base64 => {
  282. console.log(base64, "base64")
  283. mineApi.addheadimg({
  284. pic: base64
  285. }).then(res => {
  286. that.touPic = res.data.show;
  287. })
  288. })
  289. }
  290. })
  291. // #endif
  292. },
  293. goCname() {
  294. uni.navigateTo({
  295. url: '/pagesD/pages/set/cname/cname?name=' + this.name
  296. });
  297. },
  298. goChangemima() {
  299. uni.navigateTo({
  300. url: '/pagesD/pages/set/changemima/changemima'
  301. });
  302. },
  303. gorenzheng() {
  304. uni.navigateTo({
  305. url: '/pagesD/pages/set/renzheng/renzheng'
  306. });
  307. },
  308. ...mapMutations(['logout']),
  309. navTo(url) {
  310. uni.navigateTo({
  311. url: '/pagesD/pages/address/address'
  312. });
  313. },
  314. //退出登录
  315. toLogout() {
  316. uni.showModal({
  317. title: '提示',
  318. content: '确定退出登录吗?',
  319. success: e => {
  320. if (e.confirm) {
  321. this.logout();
  322. setTimeout(() => {
  323. uni.clearStorage()
  324. uni.navigateBack();
  325. }, 200);
  326. }
  327. }
  328. });
  329. },
  330. //switch
  331. switchChange(e) {
  332. let statusTip = e.detail.value ? '打开' : '关闭';
  333. this.$api.msg(`${statusTip}消息推送`);
  334. },
  335. getVersionAndPlatform() {
  336. plus.runtime.getProperty(plus.runtime.appid, (inf) => {
  337. this.version = inf.version
  338. });
  339. }
  340. }
  341. };
  342. </script>
  343. <style lang="scss">
  344. page {
  345. background: $page-color-base;
  346. }
  347. .portrait {
  348. width: 90upx;
  349. height: 90upx;
  350. border-radius: 50%;
  351. display: inline-block;
  352. }
  353. .upload-img {
  354. height: 100%;
  355. image {
  356. width: 60rpx;
  357. height: 60rpx;
  358. // padding: 10rpx;
  359. border: 1px solid #ccc;
  360. }
  361. }
  362. .icon {
  363. position: relative;
  364. top: 15rpx;
  365. height: 100%;
  366. image {
  367. width: 60rpx;
  368. height: 60rpx;
  369. }
  370. }
  371. .list-cell {
  372. display: flex;
  373. align-items: baseline;
  374. padding: 20upx $page-row-spacing;
  375. line-height: 60upx;
  376. position: relative;
  377. background: #fff;
  378. justify-content: center;
  379. &.log-out-btn {
  380. margin-top: 40upx;
  381. height: 80rpx;
  382. .cell-tit {
  383. color: #fff;
  384. height: 80rpx;
  385. line-height: 80rpx;
  386. text-align: center;
  387. margin-right: 0;
  388. border-radius: 10rpx;
  389. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  390. }
  391. }
  392. .left {
  393. position: absolute;
  394. right: 70rpx;
  395. font-size: 28rpx;
  396. color: #999;
  397. }
  398. &.cell-hover {
  399. background: #fafafa;
  400. }
  401. &.b-b:after {
  402. left: 30upx;
  403. }
  404. &.m-t {
  405. margin-bottom: 16rpx;
  406. }
  407. .cell-more {
  408. align-self: baseline;
  409. font-size: $font-lg;
  410. color: $font-color-light;
  411. margin-left: 10upx;
  412. }
  413. .cell-tit {
  414. flex: 1;
  415. font-size: $font-base + 2upx;
  416. color: $font-color-dark;
  417. margin-right: 10upx;
  418. }
  419. .cell-tip {
  420. font-size: $font-base;
  421. color: $font-color-light;
  422. }
  423. switch {
  424. transform: translateX(16upx) scale(0.84);
  425. }
  426. }
  427. </style>