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
|