diff --git a/src/utils/index.js b/src/utils/index.js index 3f0db5a..df45baa 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -47,6 +47,66 @@ export function parseTime(time, cFormat) { return time_str } +export function parseTime2(time, format = 'yyyy-MM-dd hh:mm:ss') { + const date = time instanceof Date ? time : new Date(time) + + const o = { + 'M+': date.getMonth() + 1, // 月份 + 'd+': date.getDate(), // 日 + 'h+': date.getHours() % 12, // 12小时 + 'H+': date.getHours(), // 24小时 + 'm+': date.getMinutes(), // 分 + 's+': date.getSeconds(), // 秒 + 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度 + 'S': date.getMilliseconds(), // 毫秒 + 'D': (() => { + switch (date.getDay()) { + case 1: + return '星期一' + case 2: + return '星期二' + case 3: + return '星期三' + case 4: + return '星期四' + case 5: + return '星期五' + case 6: + return '星期六' + case 0: + return '星期日' + default: + return String(date.getDay()) + } + })() + } + if (/(y+)/.test(format)) { + format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) + } + for (const k in o) { + if (new RegExp('(' + k + ')').test(format)) { + format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) + } + } + if (/CN/.test(format)) { + format = format.replace('CN', () => { + const now = Date.now() + const diff = (now - date) / 1000 + if (diff < 30) { + return '刚刚' + } else if (diff < 3600) { + // less 1 hour + return Math.ceil(diff / 60) + '分钟前' + } else if (diff < 3600 * 24) { + return Math.ceil(diff / 3600) + '小时前' + } else if (diff < 3600 * 24 * 2) { + return '1天前' + } + }) + } + return format +} + /** * @param {number} time * @param {string} option @@ -175,3 +235,76 @@ export const createGlobalLoading = (function() { }) } })() + +/** + * 调用浏览器的打印打印元素 + * @param {*} el + * @param {*} userStyle + * @param {*} width + */ +export function printElement(el, userStyle = {}, width) { + try { + const newWindow = window.open('打印窗口', '_blank')// 打印窗口要换成页面的url + let styles = '' + const tags = document.querySelectorAll('style') + for (const tag of tags) { + styles += `` + } + for (const { cssRules } of document.styleSheets) { + let style = '' + for (const { cssText } of cssRules) { + style += cssText + } + styles += `` + } + let userStyles = '' + for (const selector in userStyle) { + let style = '' + for (const cssKey in userStyle[selector]) { + style += `${cssKey}:${userStyle[selector][cssKey]};` + } + userStyles += `${selector}{${style}}` + } + styles += `` + const docStr = el.outerHTML + newWindow.document.write(` + +
+ + + ${styles} + + + ${docStr} + + + `) + newWindow.document.close() + newWindow.print() + newWindow.close() + } catch (e) { + console.log(e) + } +} \ No newline at end of file diff --git a/src/views/forceNotice/component/SpeList.vue b/src/views/forceNotice/component/SpeList.vue index a2c7f13..a6336e1 100644 --- a/src/views/forceNotice/component/SpeList.vue +++ b/src/views/forceNotice/component/SpeList.vue @@ -88,7 +88,7 @@ export default { showOverflowTooltip: true, width: '200px', formatter: (row, column, cellValue, index) => { - return `${row.uniscid || row.regNO || ''}` + return `${row.uniscId || row.regNO || ''}` } }, showInTable: this.params !== 'force' @@ -104,7 +104,7 @@ export default { showOverflowTooltip: true, width: '280px', formatter: (row, column, cellValue, index) => { - return `${row.entname || ''}` + return `${row.entName || ''}` } }, showInTable: this.params !== 'force' diff --git a/src/views/forceNotice/force/doc.vue b/src/views/forceNotice/force/doc.vue index 7c23d08..77e87ec 100644 --- a/src/views/forceNotice/force/doc.vue +++ b/src/views/forceNotice/force/doc.vue @@ -18,7 +18,7 @@