You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
apply-assistant-v3/main.js

378 lines
13 KiB
JavaScript

12 months ago
import App from './App'
import Vue from 'vue'
import './uni.promisify.adaptor'
import uView from './uni_modules/vk-uview-ui';
import G from './utils/common.js';
import Ajax from './utils/ajax.js';
11 months ago
import wyyx from './utils/wyyx.js';
12 months ago
import apiInfo from './api/index.js';
import gListApply from './components/list/apply.vue';
import gPanelFormItem from './components/panel/formItem.vue';
import gPanelCardNum from './components/panel/numCard.vue';
import gPanelCardInfo from './components/panel/infoCard.vue';
import gPanelHr from './components/panel/hr.vue';
import gPanelDetailItem from './components/panel/detailItem.vue';
import gPanelTime from './components/panel/time.vue';
11 months ago
import gFilter from './pages/home/child/filter.vue';
11 months ago
import { createSSRApp } from 'vue'
export function createApp () {
const app = createSSRApp(App)
app.config.productionTip = false;
12 months ago
11 months ago
app.component('g-list-apply', gListApply);
app.component('g-panel-form-item', gPanelFormItem);
app.component('g-panel-card-num', gPanelCardNum);
app.component('g-panel-card-info', gPanelCardInfo);
app.component('g-panel-hr', gPanelHr);
app.component('g-panel-detail-item', gPanelDetailItem);
app.component('g-panel-time', gPanelTime);
11 months ago
app.component('g-filter', gFilter);
12 months ago
11 months ago
app.config.globalProperties.api = apiInfo;
app.config.globalProperties.G = Object.assign(G, Ajax, {
/*
* 检查token,获取最新登录者信息
*/
checkToken () {
return new Promise((resolve, reject) => {
G.Get('/checkToken', '', (res) => {
uni.setStorageSync("apply-userinfo", res)
5 months ago
uni.setStorageSync("apply-uid", res.id)
11 months ago
uni.setStorageSync('apply-userinfo-copy', JSON.stringify(res));
uni.setStorageSync("apply-agencyId", res.user.agencyId); // 单独存储 -- 代理id方便获取
uni.setStorageSync("apply-supplierAccount", res.supplierAccount); // 单独存储 -- 是否是发单号,方便获取 0.不是发单号 1.是发单号
9 months ago
if (res.agencyId) {
2 months ago
G.Get('/yishoudan/agency/role/checkDeptAdmin', {}, (val) => {
console.log('/yishoudan/agency/role/checkDeptAdmin', val);
uni.setStorageSync("is_teamleader", val === true ? 1 : 0); // 是否是部门管理员的判断
})
10 months ago
G.Get(apiInfo.login_agencyInfo, {}, (aRes) => {
uni.setStorageSync("agencyInfo", aRes.agency); // 1是创建者 2是普通成员
uni.setStorageSync("IS_CREATOR", aRes.agency.userId == res.user.id || res.admin == true ? 1 : 2); // 1是创建者 2是普通成员
// 登录跳转到首页的判断
uni.setStorageSync("SHOW_INVITE", 1);
resolve(res)
});
} else {
resolve(res)
10 months ago
}
12 months ago
11 months ago
},
function fail (err) {
5 months ago
// console.log(err);
11 months ago
resolve(err)
8 months ago
}
)
12 months ago
})
11 months ago
},
/*
* 新的检查token,获取最新登录者信息
*/
checkTokenNew () {
return new Promise((resolve, reject) => {
G.Get('/appLoginByToken', '', (res) => {
uni.setStorageSync("apply-userinfo", res)
uni.setStorageSync('apply-userinfo-copy', JSON.stringify(res));
uni.setStorageSync("apply-agencyId", res.user.agencyId); // 单独存储 -- 代理id方便获取
uni.setStorageSync("apply-supplierAccount", res.supplierAccount); // 单独存储 -- 是否是发单号,方便获取 0.不是发单号 1.是发单号
9 months ago
if (res.agencyId) {
8 months ago
// if (res.agencyStatus == 1) {
10 months ago
G.Get(apiInfo.login_agencyInfo, {}, (aRes) => {
uni.setStorageSync("agencyInfo", aRes.agency); // 1是创建者 2是普通成员
uni.setStorageSync("IS_CREATOR", aRes.agency.userId == res.user.id || res.admin == true ? 1 : 2); // 1是创建者 2是普通成员
// 登录跳转到首页的判断
uni.setStorageSync("SHOW_INVITE", 1);
resolve(res)
});
} else {
resolve(res)
10 months ago
}
11 months ago
})
})
},
12 months ago
11 months ago
/*
*/
uploadImg (callback = () => { }, type = 'default', $num = 1, $sourceType = ['album', 'camera']) {
G.uploadImage($num, (imgRes) => {
uni.showLoading({
title: '上传中...',
})
12 months ago
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
11 months ago
filePath: JSON.parse(imgRes)[0],
12 months ago
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
11 months ago
let imageStr = ''
imageStr = JSON.parse(res.data).data;
if (type == 'idcard') {
// 调用身份证识别
uni.uploadFile({
url: G.ajaxUrl + apiInfo.getIDcard,
filePath: JSON.parse(imgRes)[0],
name: 'uploadFile',
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: (uploadFileRes) => {
let cardData = {
status: '上传成功',
image: imageStr,
info: JSON.parse(uploadFileRes.data).data
}
uni.hideLoading()
callback(cardData);
}
});
} else {
uni.hideLoading()
12 months ago
callback({
status: '上传成功',
11 months ago
image: imageStr
12 months ago
});
}
},
11 months ago
fail: function (res) { },
12 months ago
});
11 months ago
}, $sourceType);
},
9 months ago
11 months ago
/*
*/
uploadImgByCamera (callback = () => { }, type = 'default', $num = 1, $sourceType = ['camera']) {
11 months ago
var that = this;
11 months ago
G.uploadImage($num, (imgRes) => {
uni.showLoading({
title: '上传中...',
})
if (type == 'idcard') {
that.recognizeTmpIDcard(imgRes, (cardData) => {
callback(cardData);
})
} else {
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
filePath: JSON.parse(imgRes)[0],
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
let imageStr = ''
imageStr = JSON.parse(res.data).data;
uni.hideLoading()
callback({
status: '上传成功',
image: imageStr
});
},
fail: function (res) { },
});
10 months ago
}
11 months ago
}, $sourceType);
},
/*
2 months ago
*/
11 months ago
uploadImgByAlbum (callback = () => { }, type = 'default', $num = 1, $sourceType = ['album']) {
var that = this;
G.uploadImage($num, (imgRes) => {
uni.showLoading({
title: '上传中...',
})
if (type == 'idcard') {
that.recognizeTmpIDcard(imgRes, (cardData) => {
callback(cardData);
})
} else {
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
filePath: JSON.parse(imgRes)[0],
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
let imageStr = ''
imageStr = JSON.parse(res.data).data;
uni.hideLoading()
callback({
status: '上传成功',
image: imageStr
});
},
fail: function (res) { },
});
}
}, $sourceType);
},
11 months ago
/**
8 months ago
* 上传到oss
*/
uploadImgToOss (callback = () => { }, customDir = '', type = 'default', $num = 1, $sourceType = ['album', 'camera']) {
var that = this;
G.uploadImage($num, (imgRes) => {
uni.showLoading({
title: '上传中...',
})
5 months ago
// console.log('imgRes', imgRes);
8 months ago
let imgPath = JSON.parse(imgRes)[0]
5 months ago
// console.log('imgPath', imgPath);
8 months ago
G.Get(apiInfo.getOssInfo, { prefix: customDir }, ({ data }) => {
5 months ago
// console.log('uploadImgToOssresresresres', data);
8 months ago
const { policy, signature, accessid, dir, host } = data;
let key = dir + that.getUUID()
const formData = {
"key": key + "_${filename}",
"policy": policy,
"OSSAccessKeyId": accessid,
signature,
"success_action_status": "200",
};
uni.uploadFile({
url: host,
filePath: imgPath,
name: "file",
formData: formData,
success: function (res) {
if (res.errMsg = "uploadFile:ok") {
const imgUrl = `${host}/${key}_${imgPath.split('/').pop()}`;
callback({
status: '上传成功',
image: imgUrl
});
}
5 months ago
// console.log('resresresresresresres', res);
8 months ago
},
fail: function (res) { },
});
})
})
},
/**
11 months ago
* 上传临时文件(不需要选择图库)
*/
uploadTmpImg ($fileName, callback = () => { }) {
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
filePath: $fileName,
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
let imageStr = ''
imageStr = JSON.parse(res.data).data;
callback({
status: '上传成功',
image: imageStr
});
},
fail: function (res) { },
});
},
11 months ago
/**
* 识别临时身份证文件
*/
recognizeTmpIDcard ($fileName, callback = () => { }) {
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
filePath: Array.isArray($fileName) ? $fileName[0] : JSON.parse($fileName)[0],
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
let imageStr = ''
imageStr = JSON.parse(res.data).data;
uni.uploadFile({
url: G.ajaxUrl + apiInfo.getIDcard,
filePath: Array.isArray($fileName) ? $fileName[0] : JSON.parse($fileName)[0],
name: 'uploadFile',
header: Object.assign({
11 months ago
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
11 months ago
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: (uploadFileRes) => {
let cardData = {
status: '上传成功',
image: imageStr,
11 months ago
info: JSON.parse(uploadFileRes.data).data
11 months ago
}
uni.hideLoading()
callback(cardData);
}
});
},
fail: function (res) { },
});
},
11 months ago
/*
*/
uploadMedia (callback = () => { }, type = 'default', $num = 9) {
G.uploadM($num, (imgRes) => {
uni.showLoading({
title: '上传中...',
})
let args = Array.from(JSON.parse(imgRes));
let imgList = []
args.forEach((item, index) => {
uni.uploadFile({
url: G.ajaxUrl + apiInfo.uploadImage,
method: "post",
filePath: item.tempFilePath,
name: "uploadFile",
header: Object.assign({
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
}, Ajax.setPublicParams()),
formData: Ajax.setPublicParams(),
success: function (res) {
imgList.push(JSON.parse(res.data).data)
if (imgList.length == args.length) {
callback({
status: '上传成功',
imgList: imgList
});
}
},
fail: function (res) {
5 months ago
// console.log('res', res)
11 months ago
},
});
})
});
}
});
10 months ago
app.config.globalProperties.F = wyyx;
11 months ago
app.use(uView)
return {
app
12 months ago
}
11 months ago
}
12 months ago