| | |
| | | } from 'vuex' |
| | | import store from "../store"; |
| | | |
| | | import environments from '@/environments' |
| | | // import environments from '@/environments' |
| | | |
| | | const mixinsCommon = { |
| | | computed: { |
| | |
| | | 'color': '#fff' |
| | | }, |
| | | listApi: '', |
| | | regUserName: '用户-' + this.getRandomName(Math.floor(Math.random() * (6 - 2) + 3)), |
| | | regAvatarUrl: 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png', |
| | | |
| | | // regUserName: '用户-' + this.getRandomName(Math.floor(Math.random() * (6 - 2) + 3)), |
| | | // regAvatarUrl: 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png', |
| | | regUserName: '', |
| | | regAvatarUrl: '', |
| | | } |
| | | }, |
| | | methods: { |
| | |
| | | onBindinput(e) { |
| | | this.regUserName = e.detail.value; // 获取微信昵称 |
| | | }, |
| | | randomAccess(min, max) { |
| | | return Math.floor(Math.random() * (min - max) + max) |
| | | }, |
| | | getRandomName(NameLength) { |
| | | let name = "" |
| | | for (let i = 0; i < NameLength; i++) { |
| | | let unicodeNum = "" |
| | | unicodeNum = this.randomAccess(0x4e00, 0x9fa5).toString(16) |
| | | name += this.decodeUnicode(unicodeNum) |
| | | } |
| | | return name |
| | | }, |
| | | decodeUnicode(str) { |
| | | //Unicode显示方式是\u4e00 |
| | | str = "\\u" + str |
| | | str = str.replace(/\\/g, "%"); |
| | | //转换中文 |
| | | str = unescape(str); |
| | | //将其他受影响的转换回原来 |
| | | str = str.replace(/%/g, "\\"); |
| | | return str; |
| | | }, |
| | | async onWxCheckSubmit() { |
| | | if (this.regUserName == '微信用户') { |
| | | this.$message.showToast('昵称不合规,不可以叫做:微信用户哈~') |
| | | return |
| | | } |
| | | //保存一下 |
| | | //先上传图片 |
| | | if (this.regAvatarUrl === |
| | | 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png') { |
| | | var picture = this.regAvatarUrl |
| | | //更新接口 |
| | | this.$message.showLoading() |
| | | const { |
| | | code |
| | | } = await this.$http.request('post', "/api/current/user/update", { |
| | | data: { |
| | | ...this.dto, |
| | | nickName: this.regUserName, |
| | | picture: picture |
| | | } |
| | | }) |
| | | |
| | | this.$message.hideLoading() |
| | | this.$forceUpdate() |
| | | if (code == 0) { |
| | | this.$refs.popup_info.close() |
| | | this.$message.showToast('设置成功') |
| | | this.currentInfo.picture = picture |
| | | this.currentInfo.nickName = this.regUserName |
| | | } else { |
| | | |
| | | } |
| | | } else { |
| | | this.$http.upload(this.regAvatarUrl).then(async res => { |
| | | var picture = res.data && res.data.length > 0 && res.data[0].url || '' |
| | | //更新接口 |
| | | this.$message.showLoading() |
| | | const { |
| | | code |
| | | } = await this.$http.request('post', "/api/current/user/update", { |
| | | data: { |
| | | ...this.currentInfo, |
| | | nickName: this.regUserName, |
| | | picture: picture |
| | | } |
| | | }) |
| | | |
| | | this.$message.hideLoading() |
| | | this.$forceUpdate() |
| | | if (code == 0) { |
| | | this.$refs.popup_info.close() |
| | | this.$message.showToast('设置成功') |
| | | this.currentInfo.picture = picture |
| | | this.currentInfo.nickName = this.regUserName |
| | | } else { |
| | | |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | |
| | | |
| | | async getUserProfile(e) { |
| | | this.$message.showLoading() |
| | | const res = await wx.getUserProfile({ |
| | | desc: '用于完善会员资料', |
| | | }); |
| | | console.log(res); |
| | | this.$message.hideLoading() |
| | | this.login_Wx(res.userInfo.avatarUrl, res.userInfo.nickName) |
| | | }, |
| | | login_Wx(imgurl, nickname) { |
| | | //获取openId |
| | | // /wx/jscode2session |
| | | let inviter = this.$storage.getItem('inviter') || '' |
| | | let inviterName = this.$storage.getItem('inviterName') || '' |
| | | //有效24小时 |
| | | if (inviter) { |
| | | var inviterTime = this.$storage.getItem('inviterTime') |
| | | if (new Date().getTime() > parseInt(inviterTime) + 1000 * 3600 * 24) { |
| | | inviter = '' |
| | | inviterName = '' |
| | | this.$storage.removeItem('inviter') |
| | | this.$storage.removeItem('inviterTime') |
| | | this.$storage.removeItem('inviterName') |
| | | } |
| | | } |
| | | |
| | | |
| | | const tmp = this; |
| | | this.$message.showLoading() |
| | | this.openid = this.$storage.getItem('openid'); |
| | | this.tel = this.$storage.getItem('tel'); |
| | | console.log('info,info,info,info,info,info', this.openid, this.tel); |
| | | if (!!this.openid && !!this.tel) { |
| | | // this.login = true; |
| | | } else { |
| | | // this.login = false; |
| | | console.log('wx.login'); |
| | | wx.login({ |
| | | success: async res => { |
| | | if (res.code) { |
| | | //微信登录成功 已拿到code |
| | | // tmp.login = true; |
| | | // tmp.jsCode = res.code; //保存获取到的code |
| | | console.log('abcd', res.code); |
| | | // this.$http.request('post',`/api/login/wechat`,{data:{code:tmp.jsCode}}) |
| | | this.$storage.setItem('jsCode', res.code); |
| | | const res2 = await wx.getUserInfo(); |
| | | console.log('res', res2); |
| | | this.tcode = res.code || '' |
| | | // if (nickname == '微信用户' || true) { |
| | | // //跳出弹出框,获取具体用户信息 |
| | | // tmp.$message.hideLoading() |
| | | |
| | | // this.$refs.popup_info.open() |
| | | |
| | | // } else { |
| | | await this.$store.dispatch('loginwx', { |
| | | code: res.code, |
| | | imgurl: imgurl, |
| | | nickname: nickname, |
| | | inviter: inviter |
| | | }); |
| | | tmp.$message.hideLoading() |
| | | this.$forceUpdate() |
| | | //延迟,如果用户昵称是微信用户的话? |
| | | |
| | | setTimeout(() => { |
| | | if (tmp.currentInfo && tmp.currentInfo.id) { |
| | | if (tmp.currentInfo.nickName == '微信用户') { |
| | | tmp.$refs.popup_info && tmp.$refs.popup_info.open() |
| | | } |
| | | } |
| | | }, 500) |
| | | // } |
| | | |
| | | } else { |
| | | tmp.$message.hideLoading() |
| | | tmp.$message.showToast('微信登录失败'); |
| | | |
| | | } |
| | | }, |
| | | error: res => { |
| | | console.log('wx.login error', res); |
| | | tmp.$message.hideLoading() |
| | | |
| | | tmp.$message.showToast('微信授权失败'); |
| | | } |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | previewImg(url) { |
| | | if (url) { |
| | |
| | | } |
| | | } |
| | | // #endif |
| | | // #ifdef MP |
| | | , |
| | | async wxdownload(url, name = '') { |
| | | await this.$message.confirm('是否要下载此文件') |
| | | var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url |
| | | |
| | | let that = this |
| | | that.$message.showLoading() |
| | | // wx.sa |
| | | // wx.downloadFile({ |
| | | // url: url2, |
| | | // success: res => { |
| | | // that.$message.showToast('下载成功') |
| | | |
| | | // }, |
| | | // fail: res => { |
| | | // that.$message.showToast('下载失败') |
| | | |
| | | // }, |
| | | // complete: res => { |
| | | // that.$message.hideLoading() |
| | | // } |
| | | // }) |
| | | wx.downloadFile({ |
| | | url: url, |
| | | timeout: 120000, |
| | | success(res) { |
| | | that.$message.hideLoading() |
| | | console.log('res', res) |
| | | if (res.statusCode === 200) { |
| | | const filePath = res.tempFilePath |
| | | if (filePath.endsWith('.jpg') || |
| | | filePath.endsWith('.jpeg') || |
| | | filePath.endsWith('.png') || |
| | | filePath.endsWith('.jpg')) { |
| | | wx.saveImageToPhotosAlbum({ |
| | | filePath: filePath, |
| | | success: function (res) { |
| | | that.$message.showToast('保存图片成功') |
| | | }, |
| | | fail: function (res) { |
| | | that.$message.showToast('打开文档失败,非支持的类型') |
| | | } |
| | | }) |
| | | |
| | | } else if (filePath.endsWith('.mp4') || |
| | | filePath.endsWith('.flv') || |
| | | filePath.endsWith('.avi') || |
| | | filePath.endsWith('.wmv') || |
| | | filePath.endsWith('.mpeg')) { |
| | | wx.saveVideoToPhotosAlbum({ |
| | | filePath: filePath, |
| | | success: function (res) { |
| | | that.$message.showToast('保存视频成功') |
| | | }, |
| | | fail: function (res) { |
| | | that.$message.showToast('打开文档失败,非支持的类型') |
| | | } |
| | | }) |
| | | |
| | | } else { |
| | | wx.openDocument({ |
| | | filePath: filePath, |
| | | showMenu: true, //关键点 |
| | | success: function (res) { |
| | | console.log('打开文档成功') |
| | | }, |
| | | fail: function (res) { |
| | | that.$message.showToast('打开文档失败,非支持的类型') |
| | | } |
| | | }) |
| | | } |
| | | } else { |
| | | that.$message.showToast('下载失败,服务器内部错误') |
| | | |
| | | } |
| | | }, |
| | | fail: res => { |
| | | that.$message.hideLoading() |
| | | that.$message.showToast('下载失败') |
| | | }, |
| | | complete: res => { |
| | | |
| | | } |
| | | }) |
| | | } |
| | | // #endif |
| | | |
| | | // #ifdef PUB_CUSTOMER |
| | | , |
| | | async submitShopping(dto) { |
| | | //提交到购物车中 |
| | | this.$message.showLoading() |
| | | await this.$store.dispatch('submitShopping', dto); |
| | | this.$message.hideLoading() |
| | | } |
| | | // #endif |
| | | } |
| | | } |
| | | export default mixinsCommon |