cdk
2025-03-24 06e6cf5719a7de9d7919cee2f6fcc3cfc6f9eb9d
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
import App from './App'
 
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
import globalMixin from "@/common/globalMixin.js"
 
import store from './store'
 
//验证用户,没有登录的话直接将用户踢回到登录界面
// Vue.mixin(globalMixin)
 
Vue.config.productionTip = false
 
 
Vue.prototype.$store = store
 
Vue.prototype.$company = "广深科技"; //公司名
Vue.prototype.$esp = "/b/esp"; //存储过程路径
Vue.prototype.$api = "/api"; //API接口,用于业务请求的api
 
 
/**
 *  * 用户信息
 */
Vue.prototype.$loginInfo = {
    appName: "GSMESAP", //app名称
    sysNumber: 'GSMESAP', //MES系统中维护的APP系统编号
    forcedLogin: true, //是否需要强制登录
    hasLogin: false, //是否已经登录
    account: uni.getStorageSync('account') || '', //用户id
    userName: uni.getStorageSync('userName') || '', //用户名称
    deptNo: uni.getStorageSync('deptNo') || '', //部门号
    chineseName: uni.getStorageSync('chineseName') || '', //中文名
    id: uni.getStorageSync('id') || '' //用户id
}
 
/**
 *  * 登录
 */
Vue.prototype.$login = function () {
    this.$loginInfo.hasLogin = true;
    //写入配置文件
    try {
        uni.setStorageSync('account', this.$loginInfo.account);
        uni.setStorageSync('userName', this.$loginInfo.userName);
        uni.setStorageSync('deptNo', this.$loginInfo.deptNo);
        uni.getStorageSync('chineseName', this.$loginInfo.chineseName); //中文名
        uni.getStorageSync('id', this.$loginInfo.id); //用户id
    } catch (e) {
 
    }
}
 
/**
 *  * 设置程序标题
 */
Vue.prototype.$setTitle = function (option) {
    if (option.title) {
        this.navTitle = option.title;
        uni.setNavigationBarTitle({
            title: this.navTitle
        });
    }
}
 
/**
 *  * messageBox
 */
Vue.prototype.$showMessage = function (msg, interval) {
    if (!msg) {
        console.log('弹框信息位空,不进行实际弹框操作')
        return;
    }
    if (!interval) {
        interval = 3000; //三秒
    }
    uni.showToast({
        icon: 'none',
        title: msg,
        duration: interval,
    });
}
/**
 *  * dialog
 */
Vue.prototype.$showDialog = function (pars) {
    uni.showModal({
        title: pars.title || "提示",
        content: pars.content || "确认要操作?",
        success: (conf) => {
            if (conf.confirm) {
                if (pars.success) pars.success();
            } else {
                if (pars.fail) pars.fail();
            }
        }
    });
}
Vue.prototype.$showMessage_async = async function (msg, interval) {
    this.$showMessage(msg, interval, interval);
}
/**
 *  * 登出
 */
Vue.prototype.$logout = function () {
    this.$loginInfo.userName = "";
    this.$loginInfo.hasLogin = false;
}
/**
 *  * 获取程序菜单
 */
Vue.prototype.$getUserMenu = function (data) { //得到用户的菜单
    let _this = this;
    uni.request({
        url: _this.$store.state.serverInfo.serverAPI + '/login/getUserMenu',
        method: "POST",
        header: {
            'content-type': "application/json"
        },
        data: {
            name: _this.$loginInfo.account //用户编号
        },
        success: (res) => {
            // console.log("获取菜单");
            // console.log(res);
            if (res.data.status == 0) {
                if (data.success)
                    data.success(res.data.data.tbBillList);
            } else {
                if (data.fail) {
                    data.fail(res.data);
                } else {
                    _this.$showMessage(res.data.message);
                }
            }
        },
        fail(err) {
            _this.$showMessage("服务器断开");
        },
        complete: () => {
            if (data.complete) {
                data.complete();
            }
        }
    })
}
 
//获取url中的参数,用于页面跳转后处理主页面向子页面传参
//例如当url为http://localhost:8080/#/pages/QC/ListDemo/detail?id=5031279时
//获取到的就是params{ "id":"5031279" }
//然后通过 params["id"]就可以获取到id的值
//允许拼接多个参数
//http://localhost:8080/#/pages/QC/ListDemo/detail?id=5031279&daa001=HSC02-2308190001-1
//获取到的就是 params{ "id":"5031279","daa001":"HSC02-2308190001-1" }
Vue.prototype.$getUrlParams = function (url) {
    let params = {};
    url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (_, key, value) {
        params[key] = value;
    });
    return params;
}
 
Vue.prototype.$getDate = function (format) {
    const date = new Date();
 
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');
 
    if (format === 'yyyy-mm-dd hh24:mi:ss') {
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    } else if (format === 'yyyy-mm-dd') {
        return `${year}-${month}-${day}`;
    } else {
        return 'Invalid format';
    }
}
 
Vue.prototype.$get = function (params) {
    params.method = "get";
    params.showLoading = params.showLoading ?? true
    return this.$uni_request(params);
}
 
Vue.prototype.$post = function (params) {
    params.method = "post";
    params.showLoading = params.showLoading ?? true
    return this.$uni_request(params);
}
 
Vue.prototype.$postSyncPost = function (url, data) {
    return new Promise((resolve, reject) => {
        uni.request({
            url: this.$store.state.serverInfo.serverAPI + url,
            method: 'POST',
            data: data,
            header: {
                'content-type': 'application/json'
            },
            success: (res) => {
                resolve(res.data);
            },
            fail: (err) => {
                reject(err);
            }
        });
    });
}
 
Vue.prototype.$sendPostRequest = function (params) {
    params.method = "post";
    params.showLoading = params.showLoading ?? true
    return this.$toERP(params);
}
 
//异步方法
Vue.prototype.$toERP = function (params) {
 
    if (params.showLoading) {
        uni.showLoading({
            mask: true,
            title: (params.showLoadingTitle ? params.showLoadingTitle : "加载中...")
        });
    }
 
    let url = params.url;
    let method = params.method || "post";
    let data = params.data || {};
 
    let header = {
        'Content-Type': params.contentType
    }
 
    let _this = this;
 
    return new Promise((resolve, reject) => {
 
        uni.request({
            url: url,
            method: method,
            header: header,
            data: data,
            success(response) {
                const res = response
                // 根据返回的状态码做出对应的操作
                // 获取成功
                console.log(res);
                if (res.statusCode == 200) {
                    resolve(res.data);
                } else {
                    uni.clearStorageSync()
                    switch (res.statusCode) {
                        case 404:
                            uni.showToast({
                                title: '请求地址不存在...',
                                duration: 2000,
                            })
                            break;
                        default:
                            uni.showToast({
                                title: '请重试...',
                                duration: 2000,
                            })
                            break;
                    }
                }
            },
            fail(err) {
                console.log(err)
                if (err.errMsg.indexOf('request:fail') !== -1) {
                    uni.showToast({
                        title: '网络异常',
                        icon: "error",
                        duration: 2000
                    })
                } else {
                    uni.showToast({
                        title: '未知异常',
                        duration: 2000
                    })
                }
                reject(err);
            },
            complete() {
                // 不管成功还是失败都会执行
                uni.hideLoading();
            }
        });
    });
}
 
 
//异步方法
Vue.prototype.$uni_request = function (params) {
 
    if (params.showLoading) {
        uni.showLoading({
            mask: true,
            title: (params.showLoadingTitle ? params.showLoadingTitle : "加载中...")
        });
    }
 
    let url = params.url;
    let method = params.method || "post";
    let data = params.data || {};
 
    let header = {}
    if (method == "post") {
        header = {
            'Content-Type': 'application/json'
        };
    }
 
    let _this = this;
 
    return new Promise((resolve, reject) => {
 
        uni.request({
            url: _this.$store.state.serverInfo.serverAPI + url,
            method: method,
            header: header,
            data: data,
            success(response) {
                const res = response
                // 根据返回的状态码做出对应的操作
                // 获取成功
                console.log(res);
                if (res.statusCode == 200) {
                    if (res.data.status == 0) {
                        resolve(res.data);
                    } else {
                        uni.showToast({
                            icon: "none",
                            title: res.data.message,
                            duration: 5000,
                        });
                        resolve(res.data);
                    }
                } else {
                    uni.clearStorageSync()
                    switch (res.statusCode) {
                        case 404:
                            uni.showToast({
                                title: '请求地址不存在...',
                                duration: 2000,
                            })
                            break;
                        default:
                            uni.showToast({
                                title: '请重试...',
                                duration: 2000,
                            })
                            break;
                    }
                }
            },
            fail(err) {
                console.log(err)
                if (err.errMsg.indexOf('request:fail') !== -1) {
                    uni.showToast({
                        title: '网络异常',
                        icon: "error",
                        duration: 2000
                    })
                } else {
                    uni.showToast({
                        title: '未知异常',
                        duration: 2000
                    })
                }
                reject(err);
            },
            complete() {
                // 不管成功还是失败都会执行
                uni.hideLoading();
            }
        });
    });
}
 
 
Vue.prototype.$uni_requestNew = function (params) {
 
    if (params.showLoading) {
        uni.showLoading({
            mask: true,
            title: (params.showLoadingTitle ? params.showLoadingTitle : "加载中...")
        });
    }
 
    let url = params.url;
    let method = params.method || "post";
    let data = params.data || {};
 
    let header = {}
    if (method == "post") {
        header = {
            'Content-Type': 'application/json'
        };
    }
 
    let _this = this;
 
    return new Promise((resolve, reject) => {
 
        uni.request({
            url: url,
            method: method,
            header: header,
            data: data,
            success(response) {
                const res = response
                // 根据返回的状态码做出对应的操作
                // 获取成功
                console.log(res);
                if (res.statusCode == 200) {
                    resolve(res);
                } else {
                    uni.clearStorageSync()
                    switch (res.statusCode) {
                        case 404:
                            uni.showToast({
                                title: '请求地址不存在...',
                                duration: 2000,
                            })
                            break;
                        default:
                            uni.showToast({
                                title: '请重试...',
                                duration: 2000,
                            })
                            break;
                    }
                }
            },
            fail(err) {
                console.log(err)
                if (err.errMsg.indexOf('request:fail') !== -1) {
                    uni.showToast({
                        title: '网络异常',
                        icon: "error",
                        duration: 2000
                    })
                } else {
                    uni.showToast({
                        title: '未知异常',
                        duration: 2000
                    })
                }
                reject(err);
            },
            complete() {
                // 不管成功还是失败都会执行
                uni.hideLoading();
            }
        });
    });
}
 
 
/**
 *  * 相册选择或者照相机拍照
 */
Vue.prototype.$camera = function (params) {
    var cusMsg = {
        data: '',
        message: '',
        status: 0
    }
    uni.chooseImage({
        sizeType: params.sizeType ? params.sizeType : "original", //original 原图,compressed 压缩图 ,默认为原图
        sourceType: params.sourceType ? params.sourceType : ['camera'],
        success: (chooseImageRes) => {
            console.log(chooseImageRes);
            var tempFilePaths = chooseImageRes.tempFilePaths;
            if (!params.data) params.data = {};
            params.data.files = tempFilePaths;
            if (params.isUpload) {
                this.$upload(params);
            } else {
                cusMsg.status = true;
                cusMsg.message = "OK";
                cusMsg.data = tempFilePaths;
                if (params.success) params.success(cusMsg);
            }
        },
        fail: (err) => {
            cusMsg.status = false;
            cusMsg.message = "调用失败";
            cusMsg.data = [];
            if (params.fail) params.fail(cusMsg);
        },
        complete: () => {
            if (params.complete) params.complete();
        }
    });
}
 
Vue.prototype.$fileUpload = function (data) {
    console.log(data)
    return new Promise((resolve, reject) => {
        uni.getFileSystemManager().readFile({
            filePath: data, // 要读取的文件路径
            encoding: 'base64', // 编码格式
            success: function (res) {
                const imageData = {
                    ImageData: 'data:image/png;base64,' + res.data,
                    qsType: data.qsType,
                    fid: data.fid
                };
                // 调用你自己的上传图片接口
                uni.request({
                    url: _this.$store.state.serverInfo.serverAPI + "/Base/saveImage", // 你的上传图片接口地址
                    method: 'POST',
                    data: imageData,
                    success: function (uploadRes) {
                        console.log(uploadRes, '上传图片');
                        if (uploadRes.statusCode == 200) {
                            let group = uploadRes.data;
                            uni.showToast({
                                title: "上传成功",
                                icon: "success"
                            });
                            resolve(group); // 返回处理后数据
                        }
                    },
                    fail: function (error) {
                        reject(error);
                    }
                });
            }
        });
    });
}
 
 
App.mpType = 'app'
const app = new Vue({
    store,
    ...App
})
app.$mount()
// #endif
 
// #ifdef VUE3
import {
    createSSRApp
} from 'vue'
import {
    func
} from 'prop-types'
 
export function createApp() {
    const app = createSSRApp(App)
    return {
        app
    }
}
 
// #endif