n20-common-lib 1.3.31 → 1.3.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "1.3.31",
3
+ "version": "1.3.32",
4
4
  "private": false,
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,46 +1,22 @@
1
- const name = process.env.VUE_APP_NAME
1
+ import { addTab, closeTab, setTabName, refreshTab } from '../utils/handleTab.js'
2
2
 
3
3
  const PM = {
4
4
  namespaced: true,
5
5
  state: {
6
- data: {}
6
+ data: undefined
7
7
  },
8
8
  mutations: {
9
- set(state, data) {
10
- state.data = Object.assign({}, state.data, data)
9
+ addTab(state, opt) {
10
+ addTab(opt)
11
11
  },
12
- addTab(state, opt = {}) {
13
- window.postMessage({
14
- addTab: opt,
15
- targetName: 'main',
16
- originName: name
17
- })
12
+ closeTab(state, opt) {
13
+ closeTab(opt)
18
14
  },
19
- closeTab(state, opt = {}) {
20
- window.postMessage({
21
- closeTab: opt,
22
- targetName: 'main',
23
- originName: name
24
- })
15
+ setTabName(state, opt) {
16
+ setTabName(opt)
25
17
  },
26
- setTabName(state, opt = {}) {
27
- window.postMessage({
28
- setTabName: opt,
29
- targetName: 'main',
30
- originName: name
31
- })
32
- },
33
- refreshTab(state, opt = {}) {
34
- window.postMessage({
35
- refreshTab: opt,
36
- targetName: 'main',
37
- originName: name
38
- })
39
- }
40
- },
41
- getters: {
42
- get(state) {
43
- return state.data
18
+ refreshTab(state, opt) {
19
+ refreshTab(opt)
44
20
  }
45
21
  }
46
22
  }
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <i data-node="custom-el" style="display: none"></i>
3
+ </template>
4
+
5
+ <script>
6
+ // 触发自定义冒泡事假
7
+ // XXX:还差iframe的处理
8
+ export default {
9
+ props: {
10
+ dataCustom: {
11
+ type: Object,
12
+ default: undefined
13
+ },
14
+ dataEvent: {
15
+ type: String,
16
+ default: 'custom'
17
+ }
18
+ },
19
+ watch: {
20
+ dataCustom: {
21
+ handler(val) {
22
+ this.setData(val)
23
+ },
24
+ deep: true
25
+ }
26
+ },
27
+ mounted() {
28
+ this.setData(this.dataCustom)
29
+ },
30
+ methods: {
31
+ setData(obj) {
32
+ if (obj) {
33
+ this.$el.customData = JSON.parse(JSON.stringify(obj))
34
+ dispatchEvent(this.$el, this.dataEvent)
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ function dispatchEvent(el, type) {
41
+ var evName = '_on_' + type
42
+ var evEvent = undefined
43
+
44
+ if (!window[evName]) {
45
+ evEvent = document.createEvent('Event')
46
+ evEvent.initEvent(type, true, false)
47
+ window[evName] = evEvent
48
+ }
49
+
50
+ el.dispatchEvent(window[evName])
51
+ }
52
+ </script>
@@ -7,6 +7,25 @@
7
7
  v-bind="item.props"
8
8
  v-on="item.on"
9
9
  />
10
+ <el-input
11
+ v-else-if="item.type === 'search'"
12
+ v-model="form[item.value]"
13
+ :clearable="item | clearableF"
14
+ style="width: 100%"
15
+ readonly
16
+ v-bind="item.props"
17
+ v-on="item.on"
18
+ >
19
+ <i
20
+ slot="suffix"
21
+ class="el-input__icon el-icon-zoom-in"
22
+ @click="
23
+ () => {
24
+ item.on && item.on.focus && item.on.focus()
25
+ }
26
+ "
27
+ ></i>
28
+ </el-input>
10
29
  <el-select
11
30
  v-else-if="item.type === 'select'"
12
31
  v-model="form[item.value]"
@@ -100,6 +119,7 @@
100
119
  </template>
101
120
 
102
121
  <script>
122
+ import axios from '../../utils/axios'
103
123
  import inputNumber from '../InputNumber/index.vue'
104
124
  import inputNumberRange from '../InputNumber/numberRange.vue'
105
125
  import datePickerPor from '../DatePicker/por.vue'
@@ -127,6 +147,39 @@ export default {
127
147
  type: Object,
128
148
  default: undefined
129
149
  }
150
+ },
151
+ created() {
152
+ if (this.item.reqOptions) {
153
+ this.getOptions()
154
+ }
155
+ },
156
+ methods: {
157
+ getOptions() {
158
+ let reqOptions = this.item.reqOptions
159
+ let url = reqOptions.url || ''
160
+ url = url.includes('?')
161
+ ? `${url}r=${Math.random()}`
162
+ : `${url}?r=${Math.random()}`
163
+
164
+ axios({
165
+ ...reqOptions,
166
+ url: url,
167
+ loading: false,
168
+ noMsg: true,
169
+ resList: undefined
170
+ }).then((res) => {
171
+ let resKeys = reqOptions.resList
172
+ ? reqOptions.resList.split('.')
173
+ : ['data', 'list']
174
+
175
+ let list = res
176
+ resKeys.forEach((key) => {
177
+ list = list[key]
178
+ })
179
+
180
+ this.$set(this.item, 'options', list)
181
+ })
182
+ }
130
183
  }
131
184
  }
132
185
  </script>
@@ -6,7 +6,6 @@
6
6
  title="筛选"
7
7
  placement="bottom-end"
8
8
  @show="show"
9
- @after-leave="leave"
10
9
  >
11
10
  <template slot="reference">
12
11
  <el-button
@@ -91,7 +90,7 @@
91
90
  :columns="filterList"
92
91
  :is-filter="true"
93
92
  :auto-save="true"
94
- page-id="filterId"
93
+ :page-id="'filter:' + filterId"
95
94
  @setColumns="setRemoteChange"
96
95
  />
97
96
  </template>
@@ -170,10 +169,6 @@ export default {
170
169
  }
171
170
  })
172
171
  },
173
- leave() {
174
- this.showPopC = false
175
- this.showMore = false
176
- },
177
172
  clear() {
178
173
  this.$emit('clear')
179
174
  },
@@ -68,8 +68,8 @@ export default {
68
68
  },
69
69
  methods: {
70
70
  watchMessage(ev) {
71
- const { targetName, originName } = ev.data
72
- if (targetName === '*' && originName === 'main') {
71
+ const { updateCache, originName, targetName } = ev.data
72
+ if (updateCache && originName === 'main' && targetName === '*') {
73
73
  this.pendingRemoveCaches()
74
74
  }
75
75
  },
@@ -1,3 +1,5 @@
1
+ import { Popover as elPopover } from 'element-ui'
2
+
1
3
  let timer = undefined
2
4
  const popClass = 'at-title-pop-' + Date.now()
3
5
 
@@ -44,6 +46,9 @@ TitleDirective.install = (Vue) => {
44
46
  if (Vue.prototype.$isServer) return
45
47
  const tooltip = new Vue({
46
48
  el: document.createElement('div'),
49
+ components: {
50
+ elPopover
51
+ },
47
52
  data() {
48
53
  return {
49
54
  visible: false
@@ -1,57 +1,11 @@
1
+ import { setTabs, closeTag } from '../../utils/handleTab.js'
2
+
1
3
  // 老系统子应用调用函数,新增页签的函数接口
2
4
  export function setTabsForSub(baseUrl, to, tab = true) {
3
- let { path, name, meta = {}, query } = to
4
- let _path = baseUrl + path
5
- _path = _path.replace('//', '/')
6
- let _i18n
7
- let _title
8
-
9
- let { title, i18n } = meta
10
- if (i18n && typeof i18n === 'object') {
11
- _i18n = i18n
12
- } else if (title && typeof title === 'object') {
13
- _i18n = title
14
- } else if (name && typeof name === 'object') {
15
- _i18n = name
16
- }
17
- if (_i18n && _i18n.zh) {
18
- _title = _i18n.zh
19
- } else {
20
- _title = title
21
- }
22
-
23
- if (tab) {
24
- window.postMessage({
25
- addTabO: {
26
- path: _path,
27
- title: _title,
28
- i18n: _i18n,
29
- query: query
30
- },
31
- targetName: 'main',
32
- originName: name
33
- })
34
- } else {
35
- window.postMessage({
36
- replaceTab: {
37
- path: _path,
38
- title: _title,
39
- i18n: _i18n,
40
- query: query
41
- },
42
- targetName: 'main',
43
- originName: name
44
- })
45
- }
5
+ setTabs(baseUrl, to, tab)
46
6
  }
47
7
 
48
8
  // 老系统子应用调用函数,关闭页签的函数接口
49
9
  export function closeTagsForBackPage(url) {
50
- window.postMessage({
51
- closeTab: {
52
- path: url || window.location.pathname
53
- },
54
- targetName: 'main',
55
- originName: '*'
56
- })
10
+ closeTag(url)
57
11
  }
@@ -0,0 +1,109 @@
1
+ // 操作切换路由生成的页签
2
+ const dN = process.env.VUE_APP_NAME
3
+ /** 打开页签,push对应路由 */
4
+ export function addTab(opt = {}, name) {
5
+ window.postMessage({
6
+ addTab: opt,
7
+ targetName: 'main',
8
+ originName: name || dN
9
+ })
10
+ }
11
+ /** 子打开页签,不再push对应路由 */
12
+ export function addTabO(opt = {}, name) {
13
+ window.postMessage({
14
+ addTabO: opt,
15
+ targetName: 'main',
16
+ originName: name || dN
17
+ })
18
+ }
19
+
20
+ export function closeTab(opt = {}, name) {
21
+ window.postMessage({
22
+ closeTab: opt,
23
+ targetName: 'main',
24
+ originName: name || dN
25
+ })
26
+ }
27
+
28
+ export function setTabName(opt = {}, name) {
29
+ window.postMessage({
30
+ setTabName: opt,
31
+ targetName: 'main',
32
+ originName: name || dN
33
+ })
34
+ }
35
+
36
+ export function refreshTab(opt = {}, name) {
37
+ window.postMessage({
38
+ refreshTab: opt,
39
+ targetName: 'main',
40
+ originName: name || dN
41
+ })
42
+ }
43
+ /** 不打开页签,替换当前页签保存的路由信息 */
44
+ export function replaceTab(opt = {}, name) {
45
+ window.postMessage({
46
+ replaceTab: opt,
47
+ targetName: 'main',
48
+ originName: name || dN
49
+ })
50
+ }
51
+
52
+ /* 业务应用 */
53
+ // 获取页签名称
54
+ function getI18n(meta = {}, name) {
55
+ let _i18n = undefined
56
+ let { title, i18n } = meta
57
+
58
+ if (i18n && typeof i18n === 'object') {
59
+ _i18n = i18n
60
+ } else if (title && typeof title === 'object') {
61
+ _i18n = title
62
+ } else if (name && typeof name === 'object') {
63
+ _i18n = name
64
+ }
65
+ return {
66
+ i18n: _i18n,
67
+ title: _i18n && _i18n.zh ? _i18n.zh : title
68
+ }
69
+ }
70
+ // 获取绝对路径
71
+ function getPath(baseUrl, path) {
72
+ return (baseUrl + path).replace('//', '/')
73
+ }
74
+ // 获取模块名称
75
+ function getName(baseUrl) {
76
+ return dN || baseUrl.replace('/', '')
77
+ }
78
+ /** 子模块在门户中打开页签 */
79
+ export function setTabs(baseUrl, to, tab = true) {
80
+ let { path, name, meta = {}, query } = to
81
+ let { i18n, title } = getI18n(meta, name)
82
+ let route = getPath(baseUrl, path)
83
+
84
+ if (tab) {
85
+ addTabO(
86
+ {
87
+ path: route,
88
+ title: title,
89
+ i18n: i18n,
90
+ query: query
91
+ },
92
+ getName(baseUrl)
93
+ )
94
+ } else {
95
+ replaceTab(
96
+ {
97
+ path: route,
98
+ title: title,
99
+ i18n: i18n,
100
+ query: query
101
+ },
102
+ getName(baseUrl)
103
+ )
104
+ }
105
+ }
106
+ /** 子模块关闭在门户中的页签 */
107
+ export function closeTag(url, name) {
108
+ closeTab({ path: url || window.location.pathname }, name || '*')
109
+ }
@@ -0,0 +1,92 @@
1
+ import ExcelJS from 'exceljs'
2
+
3
+ function toExcel({ columns = [], rows = [], name = 'sheet01' }) {
4
+ let cols = []
5
+ columns.forEach((col) => {
6
+ if (!col.static) {
7
+ let _col = {
8
+ header: col.label,
9
+ key: col.prop,
10
+ style: col.style || {}
11
+ }
12
+
13
+ let width = col.width || col.minWidth || col['min-width'] || 0
14
+ width = Math.max(width / 8, col.label.length * 2.2 + 2)
15
+ width > 9 && (_col.width = width)
16
+
17
+ if (col.numFmt) {
18
+ _col.style.numFmt = col.numFmt
19
+ } else if (col.formatter && typeof col.formatter === 'string') {
20
+ if (/\|\s?money/.test(col.formatter)) {
21
+ _col.style.numFmt = '#,##0.00'
22
+ }
23
+ if (/\|\s?rate/.test(col.formatter)) {
24
+ _col.style.numFmt = '0.000000'
25
+ }
26
+ }
27
+
28
+ cols.push(_col)
29
+ }
30
+ })
31
+
32
+ let cL = cols.length
33
+ let rL = rows.length
34
+
35
+ const workbook = new ExcelJS.Workbook()
36
+ const worksheet = workbook.addWorksheet(name)
37
+
38
+ worksheet.columns = cols
39
+ worksheet.addRows(rows)
40
+
41
+ worksheet.views = [
42
+ {
43
+ state: 'frozen',
44
+ // xSplit: 1,
45
+ ySplit: 1
46
+ }
47
+ ]
48
+
49
+ for (let i = 0; i < cL; i++) {
50
+ worksheet.getCell(1, i + 1).style = {
51
+ fill: {
52
+ type: 'pattern',
53
+ pattern: 'solid',
54
+ fgColor: { argb: 'FFE1E1E1' }
55
+ },
56
+ alignment: {
57
+ vertical: 'middle',
58
+ horizontal: 'center'
59
+ },
60
+ font: {
61
+ bold: true
62
+ }
63
+ }
64
+ }
65
+
66
+ for (let i = 0; i < cL; i++) {
67
+ for (let j = 0; j < rL + 1; j++) {
68
+ worksheet.getCell(j + 1, i + 1).border = {
69
+ top: { style: 'thin' },
70
+ left: { style: 'thin' },
71
+ bottom: { style: 'thin' },
72
+ right: { style: 'thin' }
73
+ }
74
+ }
75
+ }
76
+
77
+ // worksheet.getColumn(1).numFmt = '#,##0.00"%"'
78
+ // worksheet.getColumn(1).numFmt = '#,##0.00'
79
+ // worksheet.getColumn(2).width = 32
80
+
81
+ return new Promise((resolve, reject) => {
82
+ workbook.xlsx
83
+ .writeBuffer()
84
+ .then((buffer) => {
85
+ resolve(buffer)
86
+ })
87
+ .catch((err) => {
88
+ reject(err)
89
+ })
90
+ })
91
+ }
92
+ export default toExcel