kyy
2025-09-05 c5592bc89dea7c2861db148af78da79dffd2eb48
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
var APIURL = "http://116.148.211.203:8083/api/";//PDA后端发布测试地址(内网)
var APIURL_PC = "http://116.148.211.203:8081/"; //PC后端的测试地址(外网)
 
var APIURL_IMAGE = APIURL_PC+"upload/";
var ISNEEDLOGIN = true;
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function () {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.rtrim = function () {
    return this.replace(/(\s*$)/g, "");
}
Vue.prototype.CHECKLOGIN = function () {
    var that = this;
    var loginInfo = {
        loginGuid: Cookies.get('loginGuid'),
        loginAccount: Cookies.get('loginAccount'),
    }
    if (!loginInfo
        || (loginInfo) == "undefined"
        || typeof (loginInfo.loginGuid) == "undefined"
        || typeof (loginInfo.loginGuid) == "undefined"
        || typeof (loginInfo.loginGuid).length < 1
    ) {
        if (ISNEEDLOGIN == true)
            window.location.href = "/UserLogin.aspx";
        return;
    }
}
Vue.prototype.Request = function (paras) {
    if (typeof (paras) == "undefined") {
        return "";
    }
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return decodeURI(returnValue);
    }
}
Vue.prototype.GetLoginInfor = function () {
    var that = this;
    var loginInfo = {
       // 从Cookies中获取登录时保存的userGuid(登录时存储的键是loginGuid)
        loginGuid: Cookies.get('loginGuid'),
        loginAccount: Cookies.get('loginAccount'),
    }
    if (!loginInfo
        || (loginInfo) == "undefined"
        || typeof (loginInfo.loginGuid) == "undefined"
        || typeof (loginInfo.loginGuid) == "undefined"
        || typeof (loginInfo.loginGuid).length < 1
    ) {
        if (ISNEEDLOGIN == true)
            window.location.href = "/UserLogin.aspx";
    }
    else {
        return loginInfo;
    }
}
/**
 * axios 
 * @param:{string}     method          请求类型,必填
 * @param:{string}     url             请求地址,必填
 * @param:{string}     params          请求参数,非必填
 * @param:{string}     variation       请求头,非必填
 **/
Vue.prototype.AxiosHttp = (method, url, params = {}, isToken = true, isPC =0) => {
    if (isPC == 0)
    {
        url = (APIURL + url);
    }
    else{
        url = (APIURL_PC + url);
    }
    let headers = { 'Content-Type': 'application/json', }
    if (isToken) {
        var timestamp = (new Date()).getTime();
        var token = Cookies.get('loginGuid')
        headers['token'] = token;
    }
    if (method == 'get') {
        //   console.log("params")
        return axios({
            method: method,
            url: url,
            headers: headers,
            params: params
        }).then(res => res.data);
    } else {
        return axios({
            method: method,
            url: url,
            headers: headers,
            data: params
        }).then(res => res.data);
    }
};
//axiosRequest('get', '/user/page', {},false).then(res=>{})
//axiosRequest('post', '/user/page', {},false).then(res=>{})
 
// 添加全局v-focus指令
Vue.directive("focus", {
    //inserted: function (el, { modifiers: { noKeyboard } }) {
    //    try {
    //        const tagName = el.tagName;
    //        if (tagName !== "INPUT") {
    //            let child = el.children[0];
    //            if (child && child.tagName === "INPUT") {
    //                el = child;
    //            }
    //        }
    //        var _count = (el.children.length);
    //        if (_count > 1)
    //            el = el.children[1].children[0].children[0];
    //        else
    //            el = el.children[0].children[0].children[0];
    //        // alert(el);
    //        // 可以重新获得焦点又不弹起软键盘;xxx是el-input的ref
    //        // this.$refs[xxx].$refs.input.noKeyboardFocus(); 
    //        el.noKeyboardFocus = function () {
    //            Vue.nextTick(() => {
    //                this.focus();
    //                this.setAttribute("readonly", "readonly");
    //                var timer = null;
    //                timer = setTimeout(() => {
    //                    this.removeAttribute("readonly");
    //                    clearTimeout(timer);
    //                }, 100);
    //            });
    //        };
    //        el.focus();
    //        // v-focus.noKeyboard 不弹起软键盘
    //        if (noKeyboard) {
    //            el.setAttribute("readonly", "readonly");
    //            var timer = null;
    //            timer = setTimeout(() => {
    //                el.removeAttribute("readonly");
    //                clearTimeout(timer);
    //            }, 100);
    //        }
    //    } catch (error) {
    //        throw new Error(error);
    //    }
    //}
});
 
 
Vue.prototype.GoBack=function(){
    var _userGuid = Cookies.get('loginGuid');
    var _userAccount = Cookies.get('loginAccount');
    var _url = "/H5/Default.aspx?userGuid=" + _userGuid + "&userAccount" + _userAccount + "&tabIdx=" +  this.Request("tabIdx");
    window.location.href = _url;
    return;
    window.history.back();
}
 
 
//// 新增全局打印方法
//Vue.prototype.sendPrintMessage = function (tbBillList) {
//    const cfDetails = tbBillList.cfBarInfo.map(item => {
//        return "! 0 200 200 210 1\r\n" +
//            "PAGE - WIDTH 700 \r\n" +
//            "GAP-SENSE \r\n" +
///*            "BOX 0 0 700 180 0 \r\n" +*/
//            `T 16 0 10 10 物料编码:\r\n` +
//            `T 55 3 120 10 ${item.iteM_NO}\r\n` +
//            `T 16 0 310 10 ${item.item_name}\r\n` +
//            "T 55 2 10 42 物料规格:\r\n" +
//            `T 55 2 110 42 ${item.item_model}\r\n` +
//            "T 16 0 10 78 数量:\r\n" +
//            `T 0 5 90 78 ${item.quantity}\r\n` +
//            `T 16 5 180 78 ${item.barType}\r\n` +
//            `BARCODE 128 1 25 35 350 130 ${item.iteM_BARCODE}\r\n` +
///*            `T 0 1 350 130 ${item.iteM_BARCODE}\r\n` +*/
//            "T 55 0 10 125 创建时间:\r\n" +
//            `T 55 0 120 125 ${item.creatE_DATE}\r\n` +
//            "T 55 0 10 150 打印时间:\r\n" +
//            `T 55 0 120 150 ${item.print_date}\r\n` +
//            "B QR 580 12 M 2 U 4\r\n" +
//            `MA,${item.iteM_BARCODE}\r\n` +
//            "ENDQR\r\nFORM\r\nPRINT\r\n";
//    });
 
Vue.prototype.sendPrintMessage = function (tbBillList) {
    const cfDetails = tbBillList.cfBarInfo.map(item => {
        return "! 0 195 200 472 1\r\n" +  // 基础偏移量左移5像素
            "PAGE-WIDTH 545\r\n" +     // 页面宽度减少5像素
            "GAP-SENSE\r\n" +
 
            // 外框 - 整体左移5像素
            "BOX -3 2 543 470 2\r\n" +
            // ==================== 物料条码(第一行)====================
            "LINE -3 62 425 62 1\r\n" +
            "T 55 0 8 27 物料条码:\r\n" +
            `T 55 3 120 27 ${item.iteM_BARCODE}\r\n` +  // 物料条码值
 
            // ==================== 物料编码(第二行)====================
            "LINE -3 124 543 124 1\r\n" +
            "T 55 0 8 89 编码:\r\n" +
            `T 55 3 120 89 ${item.iteM_NO}\r\n` +  // 物料编码值
 
            // ==================== 供应商(第三行)====================
            "LINE -3 186 543 186 1\r\n" +     // 第3条分隔线(间隔62)
            "T 55 0 8 151 供应商:\r\n" +
            `T 55 3 120 151 ${item.supp_name || ''}\r\n` +  // 供应商值(假设字段名)
 
            // ==================== 物料名称(第四行)====================
            "LINE -3 248 543 248 1\r\n" +     // 第4条分隔线(间隔62)
            "T 55 0 8 213 名称:\r\n" +
            `T 55 3 120 213 ${item.item_name}\r\n` +  // 物料名称值
 
            // ==================== 规格型号(第五行)====================
            "LINE -3 310 543 310 1\r\n" +     // 第5条分隔线(间隔62)
            "T 55 0 8 275 规格:\r\n" +
            `T 55 3 120 275 ${item.item_model}\r\n` +  // 规格型号值
 
            // ==================== 仓库(第六行)====================
            "LINE -3 360 543 360 1\r\n" +     // 第6条分隔线(移至竖线顶端Y=360)
            "T 55 0 8 335 仓库:\r\n" +
            `T 55 3 120 335 ${item.depot_name || ''}\r\n` +  // 仓库值(假设字段名)
 
            // ==================== 数量和仓管员(第七行)====================
            "LINE -3 430 543 430 1\r\n" +     // 底部横线(与竖线底端对齐)
            "T 55 0 8 380 数量:\r\n" +        // 文本位置保持
            `T 55 3 120 380 ${item.quantity}\r\n` +  // 数量值
            "T 55 0 275 380 仓管员:\r\n" +    // 文本位置保持
            `T 55 3 395 380 ${item.cgy || ''}\r\n` +  // 仓管员值(假设字段名)
 
            // 中间竖线分隔(范围Y=360-430,与上下横线衔接)
            "LINE 265 430 265 360 1\r\n" +    // 竖线顶端对齐仓库行分隔线
 
            // ==================== 底部时间信息 ====================
            "T 55 0 395 440 打印时间\r\n" +  // 位置保持
            "T 55 0 8 440 " + new Date().toLocaleString('zh-CN', {  // 时间格式改为年月日时分秒
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit'
            }) + "\r\n" +
 
            // ==================== 二维码区域(左移5像素)====================
            "BOX 425 3 535 113 1\r\n" +       // 位置保持
            "B QR 430 8 M 2 U 5\r\n" +        // 位置保持
            `MA,${item.iteM_BARCODE}\r\n` +  // 使用物料条码生成二维码
            "ENDQR\r\n" +
 
            "FORM\r\n" +
            "PRINT\r\n";
    });
 
 
    let sendData = {
        Type: 'Bar',
        Barcode: tbBillList.cfBarInfo[0].iteM_BARCODE,
        Detail: cfDetails,
        Ip: tbBillList.printInfo[0].ip,
        Port: tbBillList.printInfo[0].port,
    }
 
    console.log('打印数据:', sendData);
    uni.webView.postMessage({
        data: JSON.stringify(sendData)
    })
};
 
// 新增音频播放方法
Vue.prototype.$playSound = function(type = 'success') {
    try {
        const audioMap = {
            success: '/audio/YES.wav',
            error: '/audio/NO.wav'
        };
        const audio = new Audio(audioMap[type]);
        audio.play().catch(error => {
            console.error('音频播放失败:', error);
            this.$toast.fail('提示音加载失败');
        });
    } catch (e) {
        console.error('音频初始化错误:', e);
    }
};