zhangqun 11 months ago
commit 356a83dd2c
  1. 303
      common/globalJs/request.js
  2. 4
      pages/governance/index.vue
  3. 3
      pages/index/index.vue
  4. 16
      pages/investigation/components/investigation-item2.vue
  5. 2
      pages/investigation/index.vue
  6. 36
      pages/investigation/task.vue

@ -1,112 +1,134 @@
/**
* 请求封装
*/
import $ from './globalJs'
const tokenKey = 'token'
const tokenKeyValue = ''
import $ from "./globalJs";
const tokenKey = "token";
const tokenKeyValue = "";
class Request {
constructor(config = {}) {
this.config = {};
this.config.baseUrl = config.baseUrl? config.baseUrl: '';
this.config.dataType = config.dataType? config.dataType: 'json';
this.config.responseType = config.responseType? config.responseType: 'text';
this.config.header = config.header? config.header: {};
this.config.baseUrl = config.baseUrl ? config.baseUrl : "";
this.config.dataType = config.dataType ? config.dataType : "json";
this.config.responseType = config.responseType
? config.responseType
: "text";
this.config.header = config.header ? config.header : {};
this.reqInterceptors = null;
this.resInterceptors = null;
this.interceptors = {
request: fn => {
request: (fn) => {
this.reqInterceptors = fn;
},
response: fn => {
response: (fn) => {
this.resInterceptors = fn;
}
}
},
};
}
setConfig(config = {}) {
this.config = this._deepCopy(this._merge(this.config, config));
}
// 请求封装
globalRequest(url,config, method,isForm = '') {
globalRequest(url, config, method, isForm = "") {
const _this = this;
let newConfig = this._deepCopy(this._merge(this.config, config));
let lastConfig = {};
if (this.reqInterceptors && typeof this.reqInterceptors === 'function') {
if (this.reqInterceptors && typeof this.reqInterceptors === "function") {
let reqInterceptors = this.reqInterceptors(newConfig);
if (!reqInterceptors && process.env.NODE_ENV === "development") {
console.log('请求被拦截,此消息仅在开发环境显示。')
console.log("请求被拦截,此消息仅在开发环境显示。");
return false;
} else if (Object.prototype.toString.call(reqInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(reqInterceptors) === "[object Promise]"
) {
return reqInterceptors;
}
lastConfig = this._deepCopy(reqInterceptors);
} else {
lastConfig = this._deepCopy(newConfig);
}
let header = {}
let tokenData = $.getData('token')
if(tokenData){
header[tokenKey] = tokenKeyValue + tokenData
let header = {};
let tokenData = $.getData("token");
if (tokenData) {
header[tokenKey] = tokenKeyValue + tokenData;
}
if(isForm){
header['content-type'] = 'application/x-www-form-urlencoded'
if (isForm) {
header["content-type"] = "application/x-www-form-urlencoded";
}
let fullUrl = this._formatUrl(lastConfig.baseUrl, url);
if(url.indexOf('http') != -1){
fullUrl = url
if (url.indexOf("http") != -1) {
fullUrl = url;
}
return new Promise((resolve, reject) => {
console.log(fullUrl)
uni.request({
url: fullUrl,
method:method,
method: method,
data: config,
header: header,
async complete(response) {
let res = response;
if (_this.resInterceptors && typeof _this.resInterceptors === 'function') {
let resInterceptors = _this.resInterceptors(res);
// console.log('resInterceptors-----------------',resInterceptors)
if(resInterceptors.statusCode == 401 || resInterceptors.data.code == 403){
$.toast('登录信息已过期,请重新登录')
$.removeData('token')
setTimeout(() => {
$.openNew('/pages/logIn/logIn')
},1500)
return
}else if(resInterceptors.statusCode != 200){
$.toast(resInterceptors.data.message)
}
if (!resInterceptors && resInterceptors != '') {
reject('返回值已被您拦截!');
return;
} else if (Object.prototype.toString.call(resInterceptors) === "[object Promise]") {
try {
let promiseRes = await resInterceptors;
resolve(promiseRes)
} catch (error) {
reject(error)
if (response.statusCode == 404) {
$.toast("请求地址不存在");
} else if (response.statusCode == 500) {
$.toast("服务器内部错误");
} else {
console.log("response", response.statusCode);
let res = response;
if (
_this.resInterceptors &&
typeof _this.resInterceptors === "function"
) {
let resInterceptors = _this.resInterceptors(res);
// console.log('resInterceptors-----------------',resInterceptors)
if (
resInterceptors.statusCode == 401 ||
resInterceptors.data.code == 403
) {
$.toast("登录信息已过期,请重新登录");
$.removeData("token");
setTimeout(() => {
$.openNew("/pages/logIn/logIn");
}, 1500);
return;
} else if (resInterceptors.statusCode != 200) {
$.toast(resInterceptors.data.message);
}
if (!resInterceptors && resInterceptors != "") {
reject("返回值已被您拦截!");
return;
} else if (
Object.prototype.toString.call(resInterceptors) ===
"[object Promise]"
) {
try {
let promiseRes = await resInterceptors;
resolve(promiseRes);
} catch (error) {
reject(error);
}
} else {
res = resInterceptors;
}
} else {
res = resInterceptors;
}
}
resolve(res.data);
}
},
});
})
});
}
addFile(file,success, progress) {
addFile(file, success, progress) {
const _this = this;
let newConfig = this._deepCopy(this._merge(this.config, {}));
let lastConfig = {};
if (this.reqInterceptors && typeof this.reqInterceptors === 'function') {
if (this.reqInterceptors && typeof this.reqInterceptors === "function") {
let reqInterceptors = this.reqInterceptors(newConfig);
if (!reqInterceptors && process.env.NODE_ENV === "development") {
console.log('请求被拦截,此消息仅在开发环境显示。')
console.log("请求被拦截,此消息仅在开发环境显示。");
return false;
} else if (Object.prototype.toString.call(reqInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(reqInterceptors) === "[object Promise]"
) {
return reqInterceptors;
}
lastConfig = this._deepCopy(reqInterceptors);
@ -116,98 +138,103 @@ class Request {
let fullUrl = this._formatUrl(lastConfig.baseUrl, $.imgUrl);
let header = {
// 'content-Type':'multipart/form-data'
}
};
return new Promise((resolve, reject) => {
const UploadTask = uni.uploadFile({
url : fullUrl,
url: fullUrl,
filePath: file[0].path,
header:header,
header: header,
name: $.fileImgKey,
formData: {},
async complete(response) {
let res = response;
if (_this.resInterceptors && typeof _this.resInterceptors === 'function') {
if (
_this.resInterceptors &&
typeof _this.resInterceptors === "function"
) {
let resInterceptors = _this.resInterceptors(res);
if (!resInterceptors && resInterceptors != '') {
reject('返回值已被您拦截!');
if (!resInterceptors && resInterceptors != "") {
reject("返回值已被您拦截!");
return;
} else if (Object.prototype.toString.call(resInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(resInterceptors) ===
"[object Promise]"
) {
try {
let promiseRes = await resInterceptors;
resolve(promiseRes)
resolve(promiseRes);
} catch (error) {
reject(error)
reject(error);
}
} else {
res = resInterceptors;
}
}
success(JSON.parse(res.data));
}
},
});
// 监听上传进度
if (progress) {
UploadTask.onProgressUpdate((res) => {
progress(res.progress);
})
});
}
})
});
}
// 上传图片
addImg(length = 1,success,progress,type = 1) {
addImg(length = 1, success, progress, type = 1) {
// 获取本地图片的路径
uni.chooseImage({
count: length,
// original原图compressed压缩图
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
// camera相机album相册
sourceType: ['album','camera'], // 可以指定来源是相册还是相机,默认二者都有
sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
success: (res) => {
// 显示上传动画
$.showLoading('图片上传中...');
$.showLoading("图片上传中...");
var imgs;
imgs = res.tempFilePaths
imgs = res.tempFilePaths;
// #ifdef H5
// 调用上传图片的函数
// 处理多选
// if (imgs.length > length) {
// imgs = imgs.slice(0, length);
// }
this.fileImg(imgs, 0, success, progress,type);
this.fileImg(imgs, 0, success, progress, type);
// #endif
// #ifdef APP
console.log('imgs',imgs)
console.log("imgs", imgs);
// 将新添加的图片添加到imgs_arr中
uni.compressImage({
src: imgs[0],
quality: 60, // 仅对jpg有效
success: ress => {
this.fileImg([ress.tempFilePath], 0, success, progress,type);
success: (ress) => {
this.fileImg([ress.tempFilePath], 0, success, progress, type);
},
fail: err => {
$.hideLoading('图片上传中...');
fail: (err) => {
$.hideLoading("图片上传中...");
},
complete: (msg) => {
}
complete: (msg) => {},
});
// #endif
},
complete: (err) => {
},
})
complete: (err) => {},
});
}
fileImg(imgs, index,success, progress,type) {
fileImg(imgs, index, success, progress, type) {
const _this = this;
let newConfig = this._deepCopy(this._merge(this.config, {}));
let lastConfig = {};
if (this.reqInterceptors && typeof this.reqInterceptors === 'function') {
if (this.reqInterceptors && typeof this.reqInterceptors === "function") {
let reqInterceptors = this.reqInterceptors(newConfig);
if (!reqInterceptors && process.env.NODE_ENV === "development") {
console.log('请求被拦截,此消息仅在开发环境显示。')
console.log("请求被拦截,此消息仅在开发环境显示。");
return false;
} else if (Object.prototype.toString.call(reqInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(reqInterceptors) === "[object Promise]"
) {
return reqInterceptors;
}
lastConfig = this._deepCopy(reqInterceptors);
@ -215,56 +242,61 @@ class Request {
lastConfig = this._deepCopy(newConfig);
}
let fullUrl = this._formatUrl(lastConfig.baseUrl, $.imgUrl);
if(type == 2){
fullUrl = this._formatUrl(lastConfig.baseUrl, $.imgUserIdUrl)
if (type == 2) {
fullUrl = this._formatUrl(lastConfig.baseUrl, $.imgUserIdUrl);
}
let header = {
token: $.getData('token')
}
token: $.getData("token"),
};
// 如果数组长度大于下标,说明没有上传完
if (imgs.length > index) {
var src = imgs[index];
return new Promise((resolve, reject) => {
const UploadTask = uni.uploadFile({
url : fullUrl,
url: fullUrl,
filePath: src,
header:header,
header: header,
name: $.fileImgKey,
formData: {},
async complete(response) {
let res = response;
if (_this.resInterceptors && typeof _this.resInterceptors === 'function') {
if (
_this.resInterceptors &&
typeof _this.resInterceptors === "function"
) {
let resInterceptors = _this.resInterceptors(res);
// console.log('resInterceptors',resInterceptors)
let datasJSON = JSON.parse(resInterceptors.data)
if(datasJSON.code == 1101){
let datasJSON = JSON.parse(resInterceptors.data);
if (datasJSON.code == 1101) {
}
if (!resInterceptors && resInterceptors != '') {
reject('返回值已被您拦截!');
if (!resInterceptors && resInterceptors != "") {
reject("返回值已被您拦截!");
return;
} else if (Object.prototype.toString.call(resInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(resInterceptors) ===
"[object Promise]"
) {
try {
let promiseRes = await resInterceptors;
resolve(promiseRes)
resolve(promiseRes);
} catch (error) {
reject(error)
reject(error);
}
} else {
res = resInterceptors;
}
}
success(JSON.parse(res.data));
_this.fileImg(imgs, index+1, progress)
}
_this.fileImg(imgs, index + 1, progress);
},
});
// 监听上传进度
if (progress) {
UploadTask.onProgressUpdate((res) => {
progress(res.progress);
})
});
}
})
});
// #ifdef H5
// 压缩
// lrz(src, {
@ -275,7 +307,6 @@ class Request {
// #endif
// #ifdef APP-PLUS
// #endif
} else {
$.hideLoading();
}
@ -285,7 +316,7 @@ class Request {
addVideo(url, success, progress) {
// 获取本地视频的路径
uni.chooseVideo({
sourceType: ['album', 'camera'], // 选择方式
sourceType: ["album", "camera"], // 选择方式
success: (res) => {
if (res.size > $.videoSize) {
let size = parseInt($.videoSize / 1024000);
@ -294,24 +325,26 @@ class Request {
// 显示上传动画
$.showLoading("视频上传中...");
// 调用上传视频的函数
this.fileVideo(res.tempFilePath,url,success,progress);
this.fileVideo(res.tempFilePath, url, success, progress);
}
},
fail: (res) => {
console.log(JSON.stringify(res));
},
})
});
}
fileVideo(src, url,success, progress) {
fileVideo(src, url, success, progress) {
const _this = this;
let newConfig = this._deepCopy(this._merge(this.config, {}));
let lastConfig = {};
if (this.reqInterceptors && typeof this.reqInterceptors === 'function') {
if (this.reqInterceptors && typeof this.reqInterceptors === "function") {
let reqInterceptors = this.reqInterceptors(newConfig);
if (!reqInterceptors && process.env.NODE_ENV === "development") {
console.log('请求被拦截,此消息仅在开发环境显示。')
console.log("请求被拦截,此消息仅在开发环境显示。");
return false;
} else if (Object.prototype.toString.call(reqInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(reqInterceptors) === "[object Promise]"
) {
return reqInterceptors;
}
lastConfig = this._deepCopy(reqInterceptors);
@ -327,18 +360,24 @@ class Request {
name: $.fileVideoKey,
async complete(response) {
let res = response;
if (_this.resInterceptors && typeof _this.resInterceptors === 'function') {
if (
_this.resInterceptors &&
typeof _this.resInterceptors === "function"
) {
let resInterceptors = _this.resInterceptors(res);
// console.log('resInterceptors',resInterceptors)
if (!resInterceptors && resInterceptors != '') {
reject('返回值已被您拦截!');
if (!resInterceptors && resInterceptors != "") {
reject("返回值已被您拦截!");
return;
} else if (Object.prototype.toString.call(resInterceptors) === "[object Promise]") {
} else if (
Object.prototype.toString.call(resInterceptors) ===
"[object Promise]"
) {
try {
let promiseRes = await resInterceptors;
resolve(promiseRes)
resolve(promiseRes);
} catch (error) {
reject(error)
reject(error);
}
} else {
res = resInterceptors;
@ -356,27 +395,27 @@ class Request {
$.hideLoading();
$.toast("上传超时!");
},
})
});
// 监听上传进度
if (progress) {
UploadTask.onProgressUpdate((res) => {
progress(res.progress);
})
});
}
})
});
}
_formatUrl(baseUrl, url) {
if (!baseUrl) return url;
let formatUrl = '';
const baseUrlEndsWithSlash = baseUrl.endsWith('/');
const urlStartsWithSlash = url.startsWith('/');
let formatUrl = "";
const baseUrlEndsWithSlash = baseUrl.endsWith("/");
const urlStartsWithSlash = url.startsWith("/");
if (baseUrlEndsWithSlash && urlStartsWithSlash) {
formatUrl = baseUrl + url.substring(1);
} else if (baseUrlEndsWithSlash || urlStartsWithSlash) {
formatUrl = baseUrl + url;
} else {
formatUrl = baseUrl + '/' + url;
formatUrl = baseUrl + "/" + url;
}
return formatUrl;
}
@ -384,10 +423,12 @@ class Request {
let mergeConfig = this._deepCopy(oldConfig);
if (!newConfig || !Object.keys(newConfig).length) return mergeConfig;
for (let key in newConfig) {
if (key !== 'header') {
if (key !== "header") {
mergeConfig[key] = newConfig[key];
} else {
if (Object.prototype.toString.call(newConfig[key]) === '[object Object]') {
if (
Object.prototype.toString.call(newConfig[key]) === "[object Object]"
) {
for (let headerKey in newConfig[key]) {
mergeConfig[key][headerKey] = newConfig[key][headerKey];
}
@ -400,7 +441,7 @@ class Request {
let result = Array.isArray(obj) ? [] : {};
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object') {
if (typeof obj[key] === "object") {
result[key] = this._deepCopy(obj[key]);
} else {
result[key] = obj[key];

@ -3,10 +3,10 @@
<view class="Width100 Box BorderBox">
<view class="Content BorderBox Width100">
<top-title :is-show-left="false" :title="'治理'" :rightWidth='120' class="custom_bg">
<template slot="right">
<!-- <template slot="right">
<image :src="$.imgSrc + '/mine/search.png'" @click="$.open('/pages/mine/setting')" mode="aspectFit" class="InlineBlock imgIcon"></image>
<image :src="$.imgSrc + '/mine/plus.png'" mode="aspectFit" @click="$.open('/pages/mine/notice')" class="InlineBlock imgIcon"></image>
</template>
</template> -->
</top-title>
</view>
<view class="tab">

@ -168,9 +168,8 @@
})
},
handleClick(row) {
console.log(row)
if(row.pcType == 2) {
this.$.open("/pages/investigation/task" + "?id=" + this.businessId);
this.$.open("/pages/investigation/task" + "?id=" + row.businessId);
} else {
this.$.open('/pages/map/index?businessId=' + row.businessId + '&sectionId='+ row.sectionCode + '&operator=' + row.operator +'&deptId=' + row.handleDept + '&taskName=' + row.name + '&pcType' + row.pcType)
}

@ -127,10 +127,13 @@
// item.standar = false
// break;
case "4":
item.fileList = []
let arr=item.standar.split(',')
for(let itm of arr){
item.fileList.push({url:itm,name:''})
item.fileList = []
let arr = item.standar.split(',')
for (let itm of arr) {
if (itm) {
item.fileList.push({ url: itm, name: '' })
}
}
// item.fileList = [
// // {
@ -168,7 +171,10 @@
}
console.log(arr, 4343242342423)
for (let item of arr) {
this.fileList.push({ url: item, name: '' })
if (item) {
this.fileList.push({ url: item, name: '' })
}
}
} else {
this.fileList = [];

@ -193,7 +193,7 @@
console.log(row)
if (this.tab === 1) {
if(row.pcType == 2) {
this.$.open("/pages/investigation/task" + "?id=" + this.businessId);
this.$.open("/pages/investigation/task" + "?id=" + row.businessId);
} else {
this.$.open('/pages/map/index?businessId=' + row.businessId +
'&operator=' + row.operator +

@ -3,10 +3,10 @@
<view class="Width100 Box BorderBox">
<view class="Content BorderBox Width100">
<top-title :is-show-left="true" :title="'排查'" :rightWidth="40" class="custom_bg">
<template slot="right">
<!-- <template slot="right">
<image :src="$.imgSrc + '/mine/search.png'" @click="$.open('/pages/mine/setting')"
mode="aspectFit" class="InlineBlock imgIcon" style="width: 32rpx"></image>
</template>
</template> -->
</top-title>
</view>
<view class="stepBox">
@ -727,11 +727,15 @@
let arr = []
try {
arr = v.hdPic.split(',')
// arr = arr.filter(it => it !== undefined||it !== '');
} catch (error) {
console.error(error)
}
for (let item of arr) {
this.fileList.push({ url: item, name: '' })
if (item) {
this.fileList.push({ url: item, name: '' })
}
}
} else {
this.fileList = [];
@ -1209,6 +1213,7 @@
// describecheckedArr
let indexes = [];
if (describe.length <= 0) {
console.log('来了2222')
checkedArr.map(r => {
describe.push({
hdTerm: r.id,
@ -1224,6 +1229,7 @@
let foundIndex = describe.findIndex(item1 => item1.hdTerm === idToFind);
if (foundIndex === -1) {
console.log('来了')
if (item2.checkedSelect) {
describe.push({ ...item2.checkedSelect, pcType: 1, hdTerm: item2.id, });
}
@ -1231,6 +1237,7 @@
// console.log(`: ${idToFind} describe`);
} else {
console.log('来3333333')
let obj = {
hdTerm: item2.id,
hdDesc: item2.checkedSelect ? item2.checkedSelect.hdDesc : '',
@ -1247,28 +1254,7 @@
// console.log(`describe:`, describe);
});
// describe.forEach((item1, index1) => {
// let found = false;
// checkedArr.forEach((item2, index2) => {
// if (item1.hdTerm === item2.id) {
// found = true;
// let obj = {
// hdTerm: item2.id,
// hdDesc: item2.checkedSelect ? item2.checkedSelect.hdDesc : '',
// hdPic: item2.checkedSelect ? item2.checkedSelect.hdPic : '',
// hdInfo: item2.checkedSelect ? item2.checkedSelect.hdInfo : '',
// pcType: 1
// }
// describe.splice(index1, 1, obj);
// // indexes.push({ describeIndex: index1, checkedArrIndex: index2 });
// }
// if (!found) {
// // pusharr1notFoundIncheckedArr
// describe.push({ ...item2 }); // arr1
// }
// });
// });
}
console.log("Not found in checkedArr:", notFoundIncheckedArr);

Loading…
Cancel
Save