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'; import wyyx from './utils/wyyx.js'; import apiInfo from './api/index.js'; import gEmpty from './components/empty.vue'; import gLoading from './components/loading.vue'; import gButton from './components/button.vue'; import gListJob from './components/list/job.vue'; import gListApply from './components/list/apply.vue'; import gPanelServer from './components/panel/server.vue'; import gPanelImage from './components/panel/defaultImage.vue'; import gPanelFormItem from './components/panel/formItem.vue'; import gPanelFormSlot from './components/panel/formSlot.vue'; import gPanelCardNum from './components/panel/numCard.vue'; import gPanelCardInfo from './components/panel/infoCard.vue'; import gPanelHr from './components/panel/hr.vue'; import gPanelFond from './components/panel/fond.vue'; import gPanelAbout from './components/panel/about.vue'; import gPanelDetailItem from './components/panel/detailItem.vue'; import gPanelRecord from './components/panel/record.vue'; import gPanelTime from './components/panel/time.vue'; import gPanelTabbar from './components/panel/tabbar.vue'; import gPanelFixed from './components/panel/fixed.vue'; import gFilter from './pages/home/child/filter.vue'; import { createSSRApp } from 'vue' export function createApp () { const app = createSSRApp(App) app.config.productionTip = false; app.component('g-empty', gEmpty); app.component('g-loading', gLoading); app.component('g-button', gButton); app.component('g-list-job', gListJob); app.component('g-list-apply', gListApply); app.component('g-panel-server', gPanelServer); app.component('g-panel-image', gPanelImage); app.component('g-panel-form-item', gPanelFormItem); app.component('g-panel-form-slot', gPanelFormSlot); app.component('g-panel-card-num', gPanelCardNum); app.component('g-panel-card-info', gPanelCardInfo); app.component('g-panel-hr', gPanelHr); app.component('g-panel-fond', gPanelFond); app.component('g-panel-about', gPanelAbout); app.component('g-panel-detail-item', gPanelDetailItem); app.component('g-panel-record', gPanelRecord); app.component('g-panel-time', gPanelTime); app.component('g-panel-tabbar', gPanelTabbar); app.component('g-panel-fixed', gPanelFixed); app.component('g-filter', gFilter); 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) uni.setStorageSync('apply-userinfo-copy', JSON.stringify(res)); uni.setStorageSync("apply-agencyId", res.user.agencyId); // 单独存储 -- 代理id,方便获取 uni.setStorageSync("apply-supplierAccount", res.supplierAccount); // 单独存储 -- 是否是发单号,方便获取 0.不是发单号 1.是发单号 if (res.agencyId) { 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) } }, function fail (err) { console.log(err); resolve(err) }) }) }, /* * 新的检查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.是发单号 if (res.agencyId) { // if (res.agencyStatus == 1) { 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) } }) }) }, /* 上传图片 */ uploadImg (callback = () => { }, type = 'default', $num = 1, $sourceType = ['album', 'camera']) { G.uploadImage($num, (imgRes) => { uni.showLoading({ title: '上传中...', }) 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; 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() callback({ status: '上传成功', image: imageStr }); } }, fail: function (res) { }, }); }, $sourceType); }, /* 上传图片 */ uploadImgByCamera (callback = () => { }, type = 'default', $num = 1, $sourceType = ['camera']) { 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); }, /* 上传图片 */ 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); }, /** * 上传临时文件(不需要选择图库) */ 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) { }, }); }, /** * 识别临时身份证文件 */ 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({ 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); } }); }, fail: function (res) { }, }); }, /* 上传媒体文件 */ 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) { console.log('res', res) }, }); }) }); } }); app.config.globalProperties.F = wyyx; app.use(uView) return { app } }