import { mapState } from 'vuex' import store from "../store"; // import environments from '@/environments' const mixinsCommon = { computed: { ...mapState({ hasLogin: state => { // console.log('computed hasLogin',state.hasLogin,state) return state.hasLogin || false }, selftype: state => { return (state.currentInfo || {}).type || '' }, currentInfo: state => { return state.currentInfo || {} }, cache_address: state => { return state.cache_address || {} }, cache_user: state => { return state.currentInfo || {} }, sign: state => { return state.sign || {} }, // currentEnId: state=>{ // // console.log('currentEnId',state.currentInfo.enId,state.currentInfo) // return state.currentInfo.enId || '' // } }), }, data() { return { list: [], query: {}, page: { size: 10, current: 1, total: 0, }, style: { '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: '', regAvatarUrl: '', previewImgSign:false, } }, methods: { copyTxt(txt) { uni.setClipboardData({ data: txt, //要被复制的内容 success: () => { //复制成功的回调函数 uni.showToast({ //提示 title: '复制成功' }) } }) }, onChooseavatar(e) { let self = this; let { avatarUrl } = e.detail; this.regAvatarUrl = avatarUrl console.log('avatarUrl', this.regAvatarUrl) }, onBindblur(e) { this.regUserName = e.detail.value; // 获取微信昵称 }, onBindinput(e) { this.regUserName = e.detail.value; // 获取微信昵称 }, handleContact(e) { console.log(e.detail.path) console.log(e.detail.query) }, previewImg(url) { if (url) { uni.previewImage({ urls: [url] }) } }, checkFormValues(dto, keys) { if (keys) { for (var key of keys) { if (!dto[key]) { return false } } } return true }, async refreshList(type = 'get') { this.page.current = 1 await this.getList(type) }, async getList(type = 'get') { if (this.listApi) { this.$message.showLoading() const { data } = await this.$http.request(type, this.listApi, { params: { ...this.query, ...this.page }, data: { ...this.query, ...this.page } }) if (data) { if (data && Array.isArray(data)) { this.list = data || [] this.page.total = data.length || 0 } else { if (this.page.current === 1) { this.list = data.records || [] } else { //根据id去重正常 var ids = [] var idsMap = {} for (var item of this.list) { ids.push(item.id) if (item.id) { idsMap[item.id] = item } } var hasnew = false for (var item of data.records) { if (ids.indexOf(item.id) < 0) { this.list.push(item) } else { //最好更新一下 idsMap[item.id] = { ...idsMap[item.id], ...item, //覆盖了 } hasnew = true } } if (hasnew) { this.$forceUpdate() } } this.page.total = data.total || 0 } if (this.getList_after) { this.getList_after() } } this.$message.hideLoading() } }, async getMore(type = 'get') { if (this.page.total > this.page.current * this.page.size) { this.page.current += 1 await this.getList(type) } }, backHome() { uni.reLaunch({ url: '/pages/home/home' }) }, goto(url, check = false) { if (check) { console.log('currentInfo', this.currentInfo) if (!this.currentInfo.id) { this.$message.showToast('请先登陆') return } } uni.navigateTo({ url }) }, backpage() { // this.$router.go(-1) uni.navigateBack() } // #ifdef APP || H5 , async appdownload(url, name = '') { await this.$message.confirm('确定下载此文件吗') let _this = this if (url) { // var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url // uni.downloadFile({ // url: url2, // success: (res) => { // if (res.statusCode === 200) { // _this.$message.showToast('下载成功') // } else { // console.log(res) // _this.$message.showToast('下载失败') // } // }, // fail: (res) => { // console.log(res) // _this.$message.showToast('下载失败') // } // }); _this.$message.showLoading() uni.downloadFile({ url: url, //下载地址接口返回 success: (data) => { _this.$message.hideLoading() console.log('success', data) if (data.statusCode === 200) { //文件保存到本地 uni.saveFile({ tempFilePath: data.tempFilePath, //临时路径 success: function(res) { uni.showToast({ icon: 'none', mask: true, title: '文件已保存:' + res .savedFilePath, //保存路径 duration: 2000, }); setTimeout(() => { //打开文档查看 uni.openDocument({ filePath: res.savedFilePath, success: function(res) { // console.log('打开文档成功'); } }); }, 2000) }, fail: (err) => { console.log(err); uni.showToast({ icon: 'none', mask: true, title: '下载成功保存失败', }); }, }); } }, fail: (err) => { _this.$message.hideLoading() console.log(err); uni.showToast({ icon: 'none', mask: true, title: '失败请重新下载', }); }, }); } } // #endif } } export default mixinsCommon