| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- export function pxToMm(value) {
- // var inch = value / getDPI()[0];
- let scale=1754/297;
- // var c_value = inch * 25.4;
- let result=value/scale;
- return parseFloat(result.toFixed(4));//保留四位小数
- }
- // /**
- // * 像素转换成毫米
- // * @param {number} px - 输入的像素值
- // * @returns {number} - 转换后的毫米值,保留四位小数
- // */
- // export function pxToMm(px) {
- // if (px) {
- // const DPI = getDPI(); // 获取当前设备的 DPI
- // const MM_PER_INCH = 25.4; // 每英寸毫米数
- // const mmValue = (px * MM_PER_INCH) / DPI;
- // return parseFloat(mmValue.toFixed(4)); // 保留四位小数
- // } else {
- // console.log("px", px);
- // return 0;
- // }
- // }
- // 保留整数 小数 四舍五入
- export function mmToPx(num) {
- if(num)
- {
- // console.log("num",num);
- // console.log("转换后",Math.round(1754/297*num));
- // let scale=1754/297;
- // let result=(scale*num).toFixed(4);
- // console.log("scale",scale,result);
- let scale=1754/297;
- return parseFloat((scale*num).toFixed(4)); //高 150dpi 1754 96dpi:1120 1754*2480
- // return Math.round(1754/297*num)
- }
- else
- {
- console.log("num",num);
- return 0;
- }
- }
- //获取考试背景颜色值
- export function getExamBackgroundColor(type){
- const examTypesColor = {
- "1": '#F56C6C',//期末
- "2": '#3ba272',//期中
- "3": '#ea7acb',//模拟
- "4": '#fac858',//月考
- "5": '#995fb3',//周测
- "6": '#72C0DD',//平时
- };
- const result = examTypesColor[type];
- return result;
- }
- // 获取分析报告成绩分析中默认的20个颜色
- export function getScorePerformanceAnalysis() {
- return [
- "#5470C6",
- "#3BA272",
- "#EE6666",
- "#FAC858",
- "#995FB3",
- "#72C0DD",
- "#90CB75",
- "#EA7ACB",
- "#FC8451",
- "#65789B",
- "#178BD3",
- "#26A616",
- "#A6129E",
- "#D3A141",
- "#234098",
- "#047640",
- "#B43535",
- "#848BDC",
- "#D6AF83",
- "#84313D",
- ]
- }
- // 文本截断:超过指定长度显示省略号
- export function truncateText(text, maxLength) {
- if (!text) return '';
- if (text.length > maxLength) {
- return text.substring(0, maxLength) + '...';
- }
- return text;
- }
- // 去掉小数点后面为0的 如果不为0 最多只保留2位小数
- export function getFormatNumber(numberStr) {
- // 尝试将字符串转为数字
- const num = parseFloat(numberStr);
-
- // 检查是否为NaN(非数字情况)
- if (isNaN(num)) {
- return numberStr;
- }
-
- // 检查是否为整数(小数点后全为0)
- if (num % 1 === 0) {
- return num.toString();
- }
-
- // 保留最多2位小数,并去除末尾的0
- let formatted = num.toFixed(2);
-
- // 如果小数点后都是0,则返回整数形式
- if (formatted.endsWith('.00')) {
- return formatted.split('.')[0];
- }
-
- // 去除末尾的0(如1.50 → 1.5)
- formatted = formatted.replace(/\.?0+$/, '');
-
- return formatted;
- }
- export function remainingDays(endTime) {
- if (!endTime) return null;
- const MS_PER_DAY = 24 * 60 * 60 * 1000;
- // 1) 将结束时间转为 Date 对象
- const end = new Date(endTime);
- if (isNaN(end.getTime())) return null;
- // 2) 取今天的"零点"日期(精确到日,不考虑时分秒)
- const today = new Date();
- const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate());
- // 3) 取结束日期的"零点"
- const endStart = new Date(end.getFullYear(), end.getMonth(), end.getDate());
- // 4) 计算天数差并 +1(含当天和结束天)
- const diffDays = Math.round((endStart.getTime() - todayStart.getTime()) / MS_PER_DAY);
- if (diffDays < 0) return 0; // 已过期:不显示剩余时间
- return diffDays + 1; // 18号到22号:22-18=4,加1后=5天
- }
- //时间
- export function unioformDateTransform(date, param = "time"){
- if(date){
- let strDate = new Date(date).toLocaleString('zh-CN')
- let days = strDate.split(" ")[0]
- let time = strDate.split(" ")[1]
- let year = days.split("/")[0]
- let month = days.split("/")[1]
- let day = days.split("/")[2]
- if(Number(month)<10){
- month = '0'+ month
- }
- if(Number(day)<10){
- day = '0'+day
- }
- days = year+'-'+month+'-'+day
- switch(param){
- case "day":
- return days
- case "time":
- return days + " " + time
- }
- }else{
- return ''
- }
- }
- export const fileSizeConvert = (byte)=>{
- let kbSize = 0
- let mbSize = 0
- let gbSize = 0
- kbSize = (byte / 1024)
- if(kbSize > 1024){
- mbSize = kbSize / 1024
- if(mbSize > 1024){
- gbSize = mbSize / 1024
- return gbSize.toFixed(2) + 'GB'
- }else {
- return mbSize.toFixed(2) + 'MB'
- }
- }else{
- return kbSize.toFixed(2) + 'KB'
- }
- }
- // 计算文件大小方法,如果文件可以算出 MB,就返回 MB,否则返回 KB
- export const getFileSize = (fileSize) => {
- if (!fileSize) return '0 KB'
- if (fileSize >= 1024 * 1024) {
- fileSize = Math.round(fileSize / (1024 * 1024))
- return `${fileSize} MB`
- } else {
- fileSize = Math.round(fileSize / 1024)
- return `${fileSize} KB`
- }
- }
- //部门及部门下的人
- export const getDeptTreeData = (list) => {
- if (!list || list.length === 0) return []
- const arr = []
- list.forEach(one => {
- const { name, id, groupVOS } = one
- const objectOne = {
- label: name,
- id: id,
- children: []
- }
- arr.push(objectOne)
- if (groupVOS && groupVOS.length) {
- groupVOS.forEach(two => {
- const { groupId, groupName, groupUserVOS } = two
- const objectTwo = {
- label: groupName,
- id: groupId,
- children: []
- }
- objectOne.children.push(objectTwo)
- if (groupUserVOS && groupUserVOS.length) {
- groupUserVOS.forEach((three, threeIndex) => {
- const { teacherName, teacherId, userAccount, canDel, selected } = three
- objectTwo.children.push({
- id: `${one.id}_${two.groupId}_${teacherId}_${threeIndex}`,
- label: `${teacherName}(${userAccount})`,
- targetType: 1,
- targetName: teacherName,
- targetId: teacherId,
- studentCode: null,
- roleCode: null,
- roleName: null,
- gradeCode: null,
- gradeName: null,
- subjectCode: null,
- subjectName: null,
- classIdCode: null,
- className: null,
- classType: null,
- classTypeName: null,
- departmentId: one.id,
- departmentName: one.name,
- departmentGroupId: two.groupId,
- departmentGroupName: two.groupName,
- disabled: !canDel,
- selected,
- checked:selected==1?'checked':''
- })
- })
- }
- })
- }
- })
- return arr
- }
- export const subjectTreeData = (list) => {
- if (!list || list.length === 0) return []
- const arr = []
- list.forEach(one => {
- const { subjectName, subjectCode, gradePersonVos } = one
- const objectOne = {
- label: subjectName,
- id: subjectCode,
- children: []
- }
- arr.push(objectOne)
- if (gradePersonVos && gradePersonVos.length) {
- gradePersonVos.forEach(two => {
- const { gradeName, gradeCode, personVoList } = two
- const objectTwo = {
- label: gradeName,
- id: `${subjectCode}_${gradeCode}`,
- children: []
- }
- objectOne.children.push(objectTwo)
- if (personVoList && personVoList.length) {
- personVoList.forEach((three, threeIndex) => {
- const {
- showName,
- teacherName,
- teacherId,
- userAccount,
- roleCode,
- roleName,
- gradeCode,
- gradeName,
- classIdCode,
- className,
- canDel,
- selected
- } = three
- objectTwo.children.push({
- id: `${one.subjectCode}_${two.gradeCode}_${teacherId}_${threeIndex}`,
- label: `${showName}(${userAccount})`,
- targetType: 1,
- targetName: teacherName,
- targetId: teacherId,
- studentCode: null,
- roleCode,
- roleName,
- gradeCode,
- gradeName,
- subjectCode: one.subjectCode,
- subjectName: one.subjectName,
- classIdCode,
- className,
- classType: null,
- classTypeName: null,
- departmentId: null,
- departmentName: null,
- departmentGroupId: null,
- departmentGroupName: null,
- disabled: !canDel,
- selected
- })
- })
- }
- })
- }
- })
- return arr
- }
- export const gradTreeData = (list) => {
- if (!list || list.length === 0) return []
- const arr = []
- list.forEach(one => {
- const { gradeName, gradeCode, classTypePersonVoList } = one
- const objectOne = {
- label: gradeName,
- id: gradeCode,
- children: []
- }
- arr.push(objectOne)
- if (classTypePersonVoList && classTypePersonVoList.length) {
- classTypePersonVoList.forEach(two => {
- const { classTypeName, classType, classInfoPersonVoList } = two
- const objectTwo = {
- label: classTypeName,
- id: `${gradeCode}_${classType}`,
- children: []
- }
- objectOne.children.push(objectTwo)
- if (classInfoPersonVoList && classInfoPersonVoList.length) {
- classInfoPersonVoList.forEach(three => {
- const { className, classIdCode, personVoList } = three
- const objectThree = {
- label: className,
- id: `${gradeCode}_${classType}_${classIdCode}`,
- children: []
- }
- objectTwo.children.push(objectThree)
- if (personVoList && personVoList.length) {
- personVoList.forEach((four, fourIndex) => {
- const {
- showName,
- teacherName,
- teacherId,
- userAccount,
- roleCode,
- roleName,
- courseCode,
- courseName,
- canDel,
- selected
- } = four
- objectThree.children.push({
- id: `${one.gradeCode}_${two.classType}_${three.classIdCode}_${teacherId}_${fourIndex}`,
- label: `${showName}(${userAccount})`,
- targetType: 1,
- targetName: teacherName,
- targetId: teacherId,
- studentCode: null,
- roleCode,
- roleName,
- gradeCode,
- gradeName,
- subjectCode: courseCode,
- subjectName: courseName,
- classIdCode: three.classIdCode,
- className: three.className,
- classType: two.classType,
- classTypeName: two.classTypeName,
- departmentId: null,
- departmentName: null,
- departmentGroupId: null,
- departmentGroupName: null,
- disabled: !canDel,
- selected
- })
- })
- }
- })
- }
- })
- }
- })
- return arr
- }
- export const permTreeData = (list) => {
- if (!list || list.length === 0) return []
- const arr = []
- list.forEach(one => {
- const { roleId, roleName, personVoList } = one
- const objectOne = {
- label: roleName,
- id: roleId,
- children: []
- }
- arr.push(objectOne)
- if (personVoList && personVoList.length) {
- personVoList.forEach((two, twoIndex) => {
- const {
- showName,
- teacherName,
- teacherId,
- userAccount,
- roleCode,
- roleName,
- gradeCode,
- gradeName,
- courseCode,
- courseName,
- canDel,
- selected
- } = two
- objectOne.children.push({
- id: `${one.roleId}_${teacherId}_${twoIndex}`,
- label: `${showName}(${userAccount})`,
- targetType: 1,
- targetName: teacherName,
- targetId: teacherId,
- studentCode: null,
- roleCode,
- roleName,
- gradeCode,
- gradeName,
- subjectCode: courseCode,
- subjectName: courseName,
- classIdCode: null,
- className: null,
- classType: null,
- classTypeName: null,
- departmentId: null,
- departmentName: null,
- departmentGroupId: null,
- departmentGroupName: null,
- disabled: !canDel,
- selected
- })
- })
- }
- })
- return arr
- }
|