common.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. export function pxToMm(value) {
  2. // var inch = value / getDPI()[0];
  3. let scale=1754/297;
  4. // var c_value = inch * 25.4;
  5. let result=value/scale;
  6. return parseFloat(result.toFixed(4));//保留四位小数
  7. }
  8. // /**
  9. // * 像素转换成毫米
  10. // * @param {number} px - 输入的像素值
  11. // * @returns {number} - 转换后的毫米值,保留四位小数
  12. // */
  13. // export function pxToMm(px) {
  14. // if (px) {
  15. // const DPI = getDPI(); // 获取当前设备的 DPI
  16. // const MM_PER_INCH = 25.4; // 每英寸毫米数
  17. // const mmValue = (px * MM_PER_INCH) / DPI;
  18. // return parseFloat(mmValue.toFixed(4)); // 保留四位小数
  19. // } else {
  20. // console.log("px", px);
  21. // return 0;
  22. // }
  23. // }
  24. // 保留整数 小数 四舍五入
  25. export function mmToPx(num) {
  26. if(num)
  27. {
  28. // console.log("num",num);
  29. // console.log("转换后",Math.round(1754/297*num));
  30. // let scale=1754/297;
  31. // let result=(scale*num).toFixed(4);
  32. // console.log("scale",scale,result);
  33. let scale=1754/297;
  34. return parseFloat((scale*num).toFixed(4)); //高 150dpi 1754 96dpi:1120 1754*2480
  35. // return Math.round(1754/297*num)
  36. }
  37. else
  38. {
  39. console.log("num",num);
  40. return 0;
  41. }
  42. }
  43. //获取考试背景颜色值
  44. export function getExamBackgroundColor(type){
  45. const examTypesColor = {
  46. "1": '#F56C6C',//期末
  47. "2": '#3ba272',//期中
  48. "3": '#ea7acb',//模拟
  49. "4": '#fac858',//月考
  50. "5": '#995fb3',//周测
  51. "6": '#72C0DD',//平时
  52. };
  53. const result = examTypesColor[type];
  54. return result;
  55. }
  56. // 获取分析报告成绩分析中默认的20个颜色
  57. export function getScorePerformanceAnalysis() {
  58. return [
  59. "#5470C6",
  60. "#3BA272",
  61. "#EE6666",
  62. "#FAC858",
  63. "#995FB3",
  64. "#72C0DD",
  65. "#90CB75",
  66. "#EA7ACB",
  67. "#FC8451",
  68. "#65789B",
  69. "#178BD3",
  70. "#26A616",
  71. "#A6129E",
  72. "#D3A141",
  73. "#234098",
  74. "#047640",
  75. "#B43535",
  76. "#848BDC",
  77. "#D6AF83",
  78. "#84313D",
  79. ]
  80. }
  81. // 文本截断:超过指定长度显示省略号
  82. export function truncateText(text, maxLength) {
  83. if (!text) return '';
  84. if (text.length > maxLength) {
  85. return text.substring(0, maxLength) + '...';
  86. }
  87. return text;
  88. }
  89. // 去掉小数点后面为0的 如果不为0 最多只保留2位小数
  90. export function getFormatNumber(numberStr) {
  91. // 尝试将字符串转为数字
  92. const num = parseFloat(numberStr);
  93. // 检查是否为NaN(非数字情况)
  94. if (isNaN(num)) {
  95. return numberStr;
  96. }
  97. // 检查是否为整数(小数点后全为0)
  98. if (num % 1 === 0) {
  99. return num.toString();
  100. }
  101. // 保留最多2位小数,并去除末尾的0
  102. let formatted = num.toFixed(2);
  103. // 如果小数点后都是0,则返回整数形式
  104. if (formatted.endsWith('.00')) {
  105. return formatted.split('.')[0];
  106. }
  107. // 去除末尾的0(如1.50 → 1.5)
  108. formatted = formatted.replace(/\.?0+$/, '');
  109. return formatted;
  110. }
  111. export function remainingDays(endTime) {
  112. if (!endTime) return null;
  113. const MS_PER_DAY = 24 * 60 * 60 * 1000;
  114. // 1) 将结束时间转为 Date 对象
  115. const end = new Date(endTime);
  116. if (isNaN(end.getTime())) return null;
  117. // 2) 取今天的"零点"日期(精确到日,不考虑时分秒)
  118. const today = new Date();
  119. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate());
  120. // 3) 取结束日期的"零点"
  121. const endStart = new Date(end.getFullYear(), end.getMonth(), end.getDate());
  122. // 4) 计算天数差并 +1(含当天和结束天)
  123. const diffDays = Math.round((endStart.getTime() - todayStart.getTime()) / MS_PER_DAY);
  124. if (diffDays < 0) return 0; // 已过期:不显示剩余时间
  125. return diffDays + 1; // 18号到22号:22-18=4,加1后=5天
  126. }
  127. //时间
  128. export function unioformDateTransform(date, param = "time"){
  129. if(date){
  130. let strDate = new Date(date).toLocaleString('zh-CN')
  131. let days = strDate.split(" ")[0]
  132. let time = strDate.split(" ")[1]
  133. let year = days.split("/")[0]
  134. let month = days.split("/")[1]
  135. let day = days.split("/")[2]
  136. if(Number(month)<10){
  137. month = '0'+ month
  138. }
  139. if(Number(day)<10){
  140. day = '0'+day
  141. }
  142. days = year+'-'+month+'-'+day
  143. switch(param){
  144. case "day":
  145. return days
  146. case "time":
  147. return days + " " + time
  148. }
  149. }else{
  150. return ''
  151. }
  152. }
  153. export const fileSizeConvert = (byte)=>{
  154. let kbSize = 0
  155. let mbSize = 0
  156. let gbSize = 0
  157. kbSize = (byte / 1024)
  158. if(kbSize > 1024){
  159. mbSize = kbSize / 1024
  160. if(mbSize > 1024){
  161. gbSize = mbSize / 1024
  162. return gbSize.toFixed(2) + 'GB'
  163. }else {
  164. return mbSize.toFixed(2) + 'MB'
  165. }
  166. }else{
  167. return kbSize.toFixed(2) + 'KB'
  168. }
  169. }
  170. // 计算文件大小方法,如果文件可以算出 MB,就返回 MB,否则返回 KB
  171. export const getFileSize = (fileSize) => {
  172. if (!fileSize) return '0 KB'
  173. if (fileSize >= 1024 * 1024) {
  174. fileSize = Math.round(fileSize / (1024 * 1024))
  175. return `${fileSize} MB`
  176. } else {
  177. fileSize = Math.round(fileSize / 1024)
  178. return `${fileSize} KB`
  179. }
  180. }
  181. //部门及部门下的人
  182. export const getDeptTreeData = (list) => {
  183. if (!list || list.length === 0) return []
  184. const arr = []
  185. list.forEach(one => {
  186. const { name, id, groupVOS } = one
  187. const objectOne = {
  188. label: name,
  189. id: id,
  190. children: []
  191. }
  192. arr.push(objectOne)
  193. if (groupVOS && groupVOS.length) {
  194. groupVOS.forEach(two => {
  195. const { groupId, groupName, groupUserVOS } = two
  196. const objectTwo = {
  197. label: groupName,
  198. id: groupId,
  199. children: []
  200. }
  201. objectOne.children.push(objectTwo)
  202. if (groupUserVOS && groupUserVOS.length) {
  203. groupUserVOS.forEach((three, threeIndex) => {
  204. const { teacherName, teacherId, userAccount, canDel, selected } = three
  205. objectTwo.children.push({
  206. id: `${one.id}_${two.groupId}_${teacherId}_${threeIndex}`,
  207. label: `${teacherName}(${userAccount})`,
  208. targetType: 1,
  209. targetName: teacherName,
  210. targetId: teacherId,
  211. studentCode: null,
  212. roleCode: null,
  213. roleName: null,
  214. gradeCode: null,
  215. gradeName: null,
  216. subjectCode: null,
  217. subjectName: null,
  218. classIdCode: null,
  219. className: null,
  220. classType: null,
  221. classTypeName: null,
  222. departmentId: one.id,
  223. departmentName: one.name,
  224. departmentGroupId: two.groupId,
  225. departmentGroupName: two.groupName,
  226. disabled: !canDel,
  227. selected,
  228. checked:selected==1?'checked':''
  229. })
  230. })
  231. }
  232. })
  233. }
  234. })
  235. return arr
  236. }
  237. export const subjectTreeData = (list) => {
  238. if (!list || list.length === 0) return []
  239. const arr = []
  240. list.forEach(one => {
  241. const { subjectName, subjectCode, gradePersonVos } = one
  242. const objectOne = {
  243. label: subjectName,
  244. id: subjectCode,
  245. children: []
  246. }
  247. arr.push(objectOne)
  248. if (gradePersonVos && gradePersonVos.length) {
  249. gradePersonVos.forEach(two => {
  250. const { gradeName, gradeCode, personVoList } = two
  251. const objectTwo = {
  252. label: gradeName,
  253. id: `${subjectCode}_${gradeCode}`,
  254. children: []
  255. }
  256. objectOne.children.push(objectTwo)
  257. if (personVoList && personVoList.length) {
  258. personVoList.forEach((three, threeIndex) => {
  259. const {
  260. showName,
  261. teacherName,
  262. teacherId,
  263. userAccount,
  264. roleCode,
  265. roleName,
  266. gradeCode,
  267. gradeName,
  268. classIdCode,
  269. className,
  270. canDel,
  271. selected
  272. } = three
  273. objectTwo.children.push({
  274. id: `${one.subjectCode}_${two.gradeCode}_${teacherId}_${threeIndex}`,
  275. label: `${showName}(${userAccount})`,
  276. targetType: 1,
  277. targetName: teacherName,
  278. targetId: teacherId,
  279. studentCode: null,
  280. roleCode,
  281. roleName,
  282. gradeCode,
  283. gradeName,
  284. subjectCode: one.subjectCode,
  285. subjectName: one.subjectName,
  286. classIdCode,
  287. className,
  288. classType: null,
  289. classTypeName: null,
  290. departmentId: null,
  291. departmentName: null,
  292. departmentGroupId: null,
  293. departmentGroupName: null,
  294. disabled: !canDel,
  295. selected
  296. })
  297. })
  298. }
  299. })
  300. }
  301. })
  302. return arr
  303. }
  304. export const gradTreeData = (list) => {
  305. if (!list || list.length === 0) return []
  306. const arr = []
  307. list.forEach(one => {
  308. const { gradeName, gradeCode, classTypePersonVoList } = one
  309. const objectOne = {
  310. label: gradeName,
  311. id: gradeCode,
  312. children: []
  313. }
  314. arr.push(objectOne)
  315. if (classTypePersonVoList && classTypePersonVoList.length) {
  316. classTypePersonVoList.forEach(two => {
  317. const { classTypeName, classType, classInfoPersonVoList } = two
  318. const objectTwo = {
  319. label: classTypeName,
  320. id: `${gradeCode}_${classType}`,
  321. children: []
  322. }
  323. objectOne.children.push(objectTwo)
  324. if (classInfoPersonVoList && classInfoPersonVoList.length) {
  325. classInfoPersonVoList.forEach(three => {
  326. const { className, classIdCode, personVoList } = three
  327. const objectThree = {
  328. label: className,
  329. id: `${gradeCode}_${classType}_${classIdCode}`,
  330. children: []
  331. }
  332. objectTwo.children.push(objectThree)
  333. if (personVoList && personVoList.length) {
  334. personVoList.forEach((four, fourIndex) => {
  335. const {
  336. showName,
  337. teacherName,
  338. teacherId,
  339. userAccount,
  340. roleCode,
  341. roleName,
  342. courseCode,
  343. courseName,
  344. canDel,
  345. selected
  346. } = four
  347. objectThree.children.push({
  348. id: `${one.gradeCode}_${two.classType}_${three.classIdCode}_${teacherId}_${fourIndex}`,
  349. label: `${showName}(${userAccount})`,
  350. targetType: 1,
  351. targetName: teacherName,
  352. targetId: teacherId,
  353. studentCode: null,
  354. roleCode,
  355. roleName,
  356. gradeCode,
  357. gradeName,
  358. subjectCode: courseCode,
  359. subjectName: courseName,
  360. classIdCode: three.classIdCode,
  361. className: three.className,
  362. classType: two.classType,
  363. classTypeName: two.classTypeName,
  364. departmentId: null,
  365. departmentName: null,
  366. departmentGroupId: null,
  367. departmentGroupName: null,
  368. disabled: !canDel,
  369. selected
  370. })
  371. })
  372. }
  373. })
  374. }
  375. })
  376. }
  377. })
  378. return arr
  379. }
  380. export const permTreeData = (list) => {
  381. if (!list || list.length === 0) return []
  382. const arr = []
  383. list.forEach(one => {
  384. const { roleId, roleName, personVoList } = one
  385. const objectOne = {
  386. label: roleName,
  387. id: roleId,
  388. children: []
  389. }
  390. arr.push(objectOne)
  391. if (personVoList && personVoList.length) {
  392. personVoList.forEach((two, twoIndex) => {
  393. const {
  394. showName,
  395. teacherName,
  396. teacherId,
  397. userAccount,
  398. roleCode,
  399. roleName,
  400. gradeCode,
  401. gradeName,
  402. courseCode,
  403. courseName,
  404. canDel,
  405. selected
  406. } = two
  407. objectOne.children.push({
  408. id: `${one.roleId}_${teacherId}_${twoIndex}`,
  409. label: `${showName}(${userAccount})`,
  410. targetType: 1,
  411. targetName: teacherName,
  412. targetId: teacherId,
  413. studentCode: null,
  414. roleCode,
  415. roleName,
  416. gradeCode,
  417. gradeName,
  418. subjectCode: courseCode,
  419. subjectName: courseName,
  420. classIdCode: null,
  421. className: null,
  422. classType: null,
  423. classTypeName: null,
  424. departmentId: null,
  425. departmentName: null,
  426. departmentGroupId: null,
  427. departmentGroupName: null,
  428. disabled: !canDel,
  429. selected
  430. })
  431. })
  432. }
  433. })
  434. return arr
  435. }