陶杰
2024-09-11 8840efb29d8818afcfd2176914bcf4811d9c60fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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: '',
        }
    },
    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