From 73f0498fce28d7baaab920a1b22b6dd7b150450e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=AC=E9=8B=86=E5=B1=BE?= <804461479@qq.com> Date: Fri, 15 Dec 2023 17:09:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E6=AF=8F=E6=97=A5=E6=89=93=E5=8D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=AF=BC=E5=87=BA=E8=B6=85=E8=BF=87=E4=B8=80?= =?UTF-8?q?=E5=A4=A9=E6=97=B6=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/src/assets/utils/index.js | 287 +++++++++--------- .../src/views/attendance/record/list.vue | 72 +++-- 2 files changed, 203 insertions(+), 156 deletions(-) diff --git a/attendance-performance-manager-ui/admin/src/assets/utils/index.js b/attendance-performance-manager-ui/admin/src/assets/utils/index.js index fa7536c4..a7b4e91a 100644 --- a/attendance-performance-manager-ui/admin/src/assets/utils/index.js +++ b/attendance-performance-manager-ui/admin/src/assets/utils/index.js @@ -1,9 +1,9 @@ -import Qs from 'qs'; -import { post, get, upload } from './ajax'; -import queue from './queue'; -import axios from 'axios'; -import cookie from './cookie'; -import httpErrorHandler from './httpErrorHandler'; +import Qs from "qs"; +import { post, get, upload } from "./ajax"; +import queue from "./queue"; +import axios from "axios"; +import cookie from "./cookie"; +import httpErrorHandler from "./httpErrorHandler"; /** * 鑾峰彇鍙傛暟鐨勭被鍨� @@ -12,7 +12,7 @@ import httpErrorHandler from './httpErrorHandler'; * @returns {string} 鍙傛暟绫诲瀷 */ export const type = (data) => { - return Object.prototype.toString.call(data).replace(/(\[object |\])/g, '') + return Object.prototype.toString.call(data).replace(/(\[object |\])/g, ""); }; /** @@ -22,7 +22,7 @@ export const type = (data) => { */ export const getLoginStatus = () => { return window.sessionStorage.isLogin; -} +}; /** * 瑙f瀽url鍙傛暟 @@ -30,9 +30,8 @@ export const getLoginStatus = () => { * @returns {object} localtion鐨剄uery瀵硅薄 */ export const query = () => { - return Qs.parse(window.location.href.split('?')[1]) -} - + return Qs.parse(window.location.href.split("?")[1]); +}; /** * 缂栫爜url鍙傛暟 @@ -41,8 +40,8 @@ export const query = () => { * @returns string */ export const encodeURI = (data) => { - return Qs.stringify(data, { arrayFormat: 'repeat', allowDots: true }); -} + return Qs.stringify(data, { arrayFormat: "repeat", allowDots: true }); +}; /** * formatterDate @@ -51,19 +50,23 @@ export const encodeURI = (data) => { * @returns {string} val 瑙f瀽鍚庣殑缁撴灉 */ export function formatterDate(time) { - if(time==='undefined'||time===null) { - return '--'} + if (time === "undefined" || time === null) { + return "--"; + } - if (!time) return '--'; + if (!time) return "--"; let date = new Date(Number(time)); - let Y = date.getFullYear() + '-'; - let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; - let D = panLeft(date.getDate()) + ' '; - let h = panLeft(date.getHours()) + ':'; - let m = panLeft(date.getMinutes()) + ':'; + let Y = date.getFullYear() + "-"; + let M = + (date.getMonth() + 1 < 10 + ? "0" + (date.getMonth() + 1) + : date.getMonth() + 1) + "-"; + let D = panLeft(date.getDate()) + " "; + let h = panLeft(date.getHours()) + ":"; + let m = panLeft(date.getMinutes()) + ":"; let s = panLeft(date.getSeconds()); return Y + M + D + h + m + s; -}; +} /** * formatterDate * @@ -91,7 +94,7 @@ export function formatterDateDay(datetime) { return Y + M + D; } return datetime; -}; +} /** * 褰撳墠鏃ユ湡鍔犲ぉ鏁板悗寰楀埌鐨勭浉搴旀棩鏈� * @param {*} day @@ -117,10 +120,9 @@ function doHandleMonth(month) { } function panLeft(num) { - return num < 10 ? '0' + num : num; + return num < 10 ? "0" + num : num; } - /** * call鏂规硶 * @@ -132,23 +134,24 @@ function panLeft(num) { */ const call = (callMethod, url, formData, config = {}) => { return new Promise((resolve, reject) => { - callMethod(url, formData, config).then(res => { - const { code, msg, data } = res; - if (code !== 1) { - reject({ - message: msg || '' - }); - return; - } - resolve(res); - }) - .catch(error => { + callMethod(url, formData, config) + .then((res) => { + const { code, msg, data } = res; + if (code !== 1) { + reject({ + message: msg || "", + }); + return; + } + resolve(res); + }) + .catch((error) => { if (error.status === 403) { - window.location.href = '/#/login' + window.location.href = "/#/login"; } reject(error); - }) - }) + }); + }); }; /** @@ -176,10 +179,10 @@ export const normalCallGet = (url, formData, config = {}) => { }; const mimeMap = { - xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - zip: 'application/zip', - doc: 'application/msword' -} + xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + zip: "application/zip", + doc: "application/msword", +}; /** * 鏅€氱殑ajax download璇锋眰 @@ -192,90 +195,107 @@ const mimeMap = { export const download = (url, formData, config = {}) => { return new Promise(async (resolve, reject) => { const option = Object.assign({}, config, { - responseType: 'blob' - }) + responseType: "blob", + }); try { - const data = await post(url, formData, option) - const link = document.createElement('a') - let blob - let extName + const data = await post(url, formData, option); + const link = document.createElement("a"); + let blob; + let extName; if (option.type == "zip") { - blob = new Blob([data], { type: mimeMap.zip }) - extName = "zip" + blob = new Blob([data], { type: mimeMap.zip }); + extName = "zip"; } else if (option.type == "excel") { - blob = new Blob([data], { type: mimeMap.xlsx }) - extName = "xlsx" + blob = new Blob([data], { type: mimeMap.xlsx }); + extName = "xlsx"; } else if (option.type == "doc") { - blob = new Blob([data], { type: mimeMap.doc }) - extName = "doc" + blob = new Blob([data], { type: mimeMap.doc }); + extName = "doc"; } else { - extName = "xlsx" + extName = "xlsx"; } - let fileName = "瀵煎嚭" + let fileName = "瀵煎嚭"; if (option.fileName) { - fileName = option.fileName + fileName = option.fileName; } - link.href = URL.createObjectURL(blob) - link.setAttribute('download', `${fileName}.${extName}`) // 璁剧疆涓嬭浇鏂囦欢鍚嶇О - document.body.appendChild(link) - link.click() - document.body.appendChild(link) + link.href = URL.createObjectURL(blob); + link.setAttribute("download", `${fileName}.${extName}`); // 璁剧疆涓嬭浇鏂囦欢鍚嶇О + document.body.appendChild(link); + link.click(); + document.body.appendChild(link); resolve(); } catch (error) { reject(error); } - }) + }); }; - export const downloadWithCustName = (url, formData, config = {}) => { return new Promise(async (resolve, reject) => { const option = Object.assign({}, config, { - responseType: 'blob', - baseURL: '/m', + responseType: "blob", + baseURL: "/m", headers: { post: { - 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' - } - } - }) + "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", + }, + }, + }); try { const params = Object.assign({}, formData, { - __mortals_token__: cookie.getItem('__mortals_token__'), - }) - var requestData = Qs.stringify(params, { arrayFormat: 'repeat', allowDots: true }); - axios.post(url, requestData, option) - .then(response => { - if (response.data.type == 'application/json') { - var reader = new FileReader(); - reader.onload = function (event) { - var content = reader.result; - reject(content); - }; - reader.readAsText(response.data); - return; + __mortals_token__: cookie.getItem("__mortals_token__"), + }); + var requestData = Qs.stringify(params, { + arrayFormat: "repeat", + allowDots: true, + }); + axios + .post(url, requestData, option) + .then( + (response) => { + if (response.data.type == "application/json") { + var reader = new FileReader(); + reader.onload = function(event) { + var content = reader.result; + reject(content); + }; + reader.readAsText(response.data); + return; + } + const filename = + decodeURI( + response.headers["content-disposition"] + .split(";")[1] + .split("=")[1] + ) || + `${url + .substr(1) + .replace(/\//g, "_")}_${new Date().getTime()}.xls`; + let downloadUrl = window.URL.createObjectURL( + new Blob([response.data]) + ); + let link = document.createElement("a"); + link.style.display = "none"; + link.href = downloadUrl; + link.setAttribute("download", filename); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + resolve(); + }, + (err) => { + reject(err); } - const filename = decodeURI(response.headers['content-disposition'].split(';')[1].split('=')[1]) || `${url.substr(1).replace(/\//g, '_')}_${new Date().getTime()}.xls` - let downloadUrl = window.URL.createObjectURL(new Blob([response.data])) - let link = document.createElement('a') - link.style.display = 'none'; - link.href = downloadUrl; - link.setAttribute('download', filename); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - resolve(); - }, err => { - reject(err); - }).catch((error) => { - reject(error) - }) + ) + .catch((error) => { + reject(error); + }); } catch (error) { reject(error); } - }) + }); }; /** @@ -309,16 +329,15 @@ export async function getUserListByQuery(query) { try { /* //涓嬫媺鍙幏鍙栨甯哥姸鎬佹暟鎹細status{0: "鍋滅敤", 1: "姝e父", 2: "鍐荤粨", 3: "閿€鎴�", 4: "绂昏亴"} query["query.status"] = 1;*/ - const data = await normalCallPost('/user/list', query); + const data = await normalCallPost("/user/list", query); const list = data.data.result.map(({ id, loginName, realName, mobile }) => { - return { id, loginName, realName, mobile } + return { id, loginName, realName, mobile }; }); return list; } catch (error) { return []; } -}; - +} /** * 鏋勯€犳爲鍨嬬粨鏋勬暟鎹� @@ -329,41 +348,48 @@ export async function getUserListByQuery(query) { * @param {*} rootId 鏍笽d 榛樿 0 */ export function handleTree(data, id, parentId, children, rootId) { - console.log("handle") - id = id || 'id' - parentId = parentId || 'parentId' - children = children || 'children' - rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 + console.log("handle"); + id = id || "id"; + parentId = parentId || "parentId"; + children = children || "children"; + rootId = + rootId || + Math.min.apply( + Math, + data.map((item) => { + return item[parentId]; + }) + ) || + 0; //瀵规簮鏁版嵁娣卞害鍏嬮殕 - const cloneData = JSON.parse(JSON.stringify(data)) + const cloneData = JSON.parse(JSON.stringify(data)); //寰幆鎵€鏈夐」 - console.log("11111", cloneData) - const treeData = cloneData.filter(father => { - let branchArr = cloneData.filter(child => { + console.log("11111", cloneData); + const treeData = cloneData.filter((father) => { + let branchArr = cloneData.filter((child) => { //杩斿洖姣忎竴椤圭殑瀛愮骇鏁扮粍 - return father[id] === child[parentId] + return father[id] === child[parentId]; }); - branchArr.length > 0 ? father.children = branchArr : ''; + branchArr.length > 0 ? (father.children = branchArr) : ""; //杩斿洖绗竴灞� return father[parentId] === rootId; }); - console.log("treeData", treeData) - return treeData != '' ? treeData : data; -}; - + console.log("treeData", treeData); + return treeData != "" ? treeData : data; +} /** - * 涓嬭浇鏂囦欢 - * @param {String} path - 涓嬭浇鍦板潃/涓嬭浇璇锋眰鍦板潃銆� - * @param {String} name - 涓嬭浇鏂囦欢鐨勫悕瀛�/閲嶅懡鍚嶏紙鑰冭檻鍒板吋瀹规€ч棶棰橈紝鏈€濂藉姞涓婂悗缂€鍚嶏級 - */ + * 涓嬭浇鏂囦欢 + * @param {String} path - 涓嬭浇鍦板潃/涓嬭浇璇锋眰鍦板潃銆� + * @param {String} name - 涓嬭浇鏂囦欢鐨勫悕瀛�/閲嶅懡鍚嶏紙鑰冭檻鍒板吋瀹规€ч棶棰橈紝鏈€濂藉姞涓婂悗缂€鍚嶏級 + */ export function downloadFile(path, name) { if (path && name) { const xhr = new XMLHttpRequest(); xhr.open("get", path); xhr.responseType = "blob"; xhr.send(); - xhr.onload = function () { + xhr.onload = function() { if (this.status === 200 || this.status === 304) { // 濡傛灉鏄疘E10鍙婁互涓婏紝涓嶆敮鎸乨ownload灞炴€э紝閲囩敤msSaveOrOpenBlob鏂规硶锛屼絾鏄疘E10浠ヤ笅涔熶笉鏀寔msSaveOrOpenBlob if ("msSaveOrOpenBlob" in navigator) { @@ -384,10 +410,8 @@ export function downloadFile(path, name) { } }; } - } - // 褰撳厓绱犳粴鍔ㄦ潯琚粴鍔ㄦ椂杩愯鐨勮剼鏈� export function handleScroll() { let scrollbarEl = this.$refs["scroll"].wrap; @@ -446,13 +470,4 @@ export function jump(index) { _this.$refs["scroll"].wrap.scrollTop = distance; } } -}; - - - - - - - - - +} diff --git a/attendance-performance-manager-ui/admin/src/views/attendance/record/list.vue b/attendance-performance-manager-ui/admin/src/views/attendance/record/list.vue index 7870cd3f..9ae18399 100644 --- a/attendance-performance-manager-ui/admin/src/views/attendance/record/list.vue +++ b/attendance-performance-manager-ui/admin/src/views/attendance/record/list.vue @@ -335,8 +335,6 @@ export default { }, /** 瀵煎嚭Excel */ doExport() { - this.isExport = true; - this.progress = true; let params = {}; for (let value of this.config.search) { if (this.query[value.name]) { @@ -349,25 +347,59 @@ export default { if (this.checkList.length > 0) { params["properties"] = this.checkList; } - this.$download( - "/attendance/record/exportExcel", - { - ...params, - }, - { type: "excel" } - ) - .then(() => { - this.percent = 100; - this.progress = false; - this.isExport = false; - this.checkList = []; - }) - .catch((error) => { - this.progress = false; + let flag = this.checkDate( + params.attendanceDateStart, + params.attendanceDateEnd, + 1 + ); + if (!flag) { + this.isExport = true; - this.isExport = false; - this.$message.error(error.message); - }); + this.progress = true; + this.$download( + "/attendance/record/exportExcel", + { + ...params, + }, + { type: "excel" } + ) + .then((res) => { + this.percent = 100; + this.progress = false; + this.isExport = false; + this.checkList = []; + }) + .catch((error) => { + this.percent = 100; + this.progress = false; + + this.isExport = false; + this.$message.error(error.message); + }); + } + }, + checkDate(startTime, endTime, compDay) { + if (startTime == "" || startTime == null || startTime == undefined) { + this.$message.error("寮€濮嬫椂闂翠负绌猴紝璇锋鏌ワ紒"); + return true; + } + if (endTime == "" || endTime == null || endTime == undefined) { + this.$message.error("缁撴潫鏃堕棿涓虹┖锛岃妫€鏌ワ紒"); + return true; + } + var data1 = Date.parse(startTime.replace(/-/g, "/")); + var data2 = Date.parse(endTime.replace(/-/g, "/")); + var datadiff = data2 - data1; + var time = parseInt(compDay) * (60 * 60 * 24 * 1000); + if (datadiff < 0) { + this.$message.error("寮€濮嬫椂闂村簲灏忎簬缁撴潫鏃堕棿"); + return true; + } + if (datadiff > time) { + this.$message.error("鏃堕棿闂撮殧澶т簬" + parseInt(compDay) + "澶╋紝璇锋鏌�!"); + return true; + } + return false; }, setdialog() { this.isdialog = true; -- 2.24.3