t20-common-lib 0.7.10 → 0.8.0

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": "t20-common-lib",
3
- "version": "0.7.10",
3
+ "version": "0.8.0",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -23,19 +23,19 @@
23
23
  "keywords": [
24
24
  "vue",
25
25
  "element-ui",
26
- "t20-common-lib"
26
+ "t20-common-lib",
27
+ "store"
27
28
  ],
28
29
  "author": "liuzongxi",
29
30
  "license": "MIT",
30
31
  "dependencies": {
31
32
  "core-js": "^2.6.12",
33
+ "dayjs": "^1.11.18",
32
34
  "element-ui": "^2.15.13",
33
- "highlight.js": "^11.11.1",
34
- "n20-common-lib": "^2.16.24",
35
35
  "normalize.css": "^8.0.1",
36
36
  "vue": "^2.6.14",
37
37
  "vue-server-renderer": "^2.6.14",
38
- "vxe-table": "^3.6.17"
38
+ "vuex": "^3.6.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/core": "^7.28.4",
@@ -60,9 +60,7 @@
60
60
  "process": "^0.11.10",
61
61
  "rimraf": "^3.0.2",
62
62
  "sass-loader": "^8.0.2",
63
- "vue-template-compiler": "^2.6.14",
64
- "vuepress": "^1.9.7",
65
- "vuepress-plugin-demo-block": "^0.7.2"
63
+ "vue-template-compiler": "^2.6.14"
66
64
  },
67
65
  "eslintConfig": {
68
66
  "root": true,
@@ -0,0 +1,8 @@
1
+ import MultiCurrencyStatistics from './src/main';
2
+
3
+ /* istanbul ignore next */
4
+ MultiCurrencyStatistics.install = function(Vue) {
5
+ Vue.component(MultiCurrencyStatistics.name, MultiCurrencyStatistics);
6
+ };
7
+
8
+ export default MultiCurrencyStatistics;
@@ -0,0 +1,229 @@
1
+ <template>
2
+ <div class="footer-static flex-box">
3
+ <N20-statis-popover v-if="!onlyAll" class="m-r-s" :lists="selectStatistics" :countLabel="[$l('条数')]" :total="selectTotal"/>
4
+ <N20-statis-popover :lists="allStatistics" :countLabel="[$l('条数')]" :total="multipleTotal"/>
5
+ </div>
6
+ </template>
7
+ <script>
8
+ export default {
9
+ name: 'MultiCurrencyStatistics',
10
+ props: {
11
+ views: {
12
+ type: Array,
13
+ default: () => []
14
+ },
15
+ config: {
16
+ type: Array,
17
+ default: () => []
18
+ },
19
+ // 选中的数据
20
+ selected: {
21
+ type: Array,
22
+ default: () => []
23
+ },
24
+ // 数据是否是在币种列表中
25
+ isMultiple: {
26
+ type: Boolean,
27
+ default: false
28
+ },
29
+ multipleKey: {
30
+ type: String,
31
+ default: 'curreyNoList'
32
+ },
33
+ onlyAll: {
34
+ type: Boolean,
35
+ default: false
36
+ },
37
+ multipleTotal: {
38
+ type: Number,
39
+ default: 0
40
+ }
41
+ },
42
+ data() {
43
+ return {
44
+ allStatistics: [],
45
+ selectStatistics: [],
46
+ selectStatisticsTpl: [],
47
+ selectTotal: 0
48
+ }
49
+ },
50
+ watch: {
51
+ selected: {
52
+ deep: true,
53
+ immediate: true,
54
+ handler() {
55
+ this.calculationSelected()
56
+ }
57
+ },
58
+ views: {
59
+ deep: true,
60
+ immediate: true,
61
+ handler() {
62
+ this.generateStatistics()
63
+ }
64
+ }
65
+ },
66
+ methods: {
67
+ /**
68
+ * 计算已选数据
69
+ */
70
+ calculationSelected() {
71
+ this.selectTotal = 0
72
+ if (!this.selected.length) {
73
+ this.selectStatistics = [this.selectStatisticsTpl[0]]
74
+ return
75
+ }
76
+ let selectedList = []
77
+ this.selectStatistics = []
78
+ this.selectTotal = this.selected.length
79
+ if (this.isMultiple) {
80
+ const arr = []
81
+ this.selected.forEach(item => {
82
+ if (item[this.multipleKey] && !arr.includes(item.accountNo)) {
83
+ item[this.multipleKey].forEach(currency => {
84
+ selectedList.push({...item, ...currency, [this.multipleKey]: undefined})
85
+ })
86
+ }
87
+ if (!arr.includes(item.accountNo)) {
88
+ arr.push(item.accountNo)
89
+ }
90
+ })
91
+ this.selectTotal = arr.length
92
+ } else {
93
+ selectedList = this.selected
94
+ }
95
+
96
+ this.selectStatisticsTpl.forEach((statistic) => {
97
+ const coins = selectedList.filter(item => {
98
+ return item.currencyName === statistic.title
99
+ })
100
+
101
+ if (coins.length) {
102
+ const statis = [
103
+ {
104
+ type: this.$l('已选合计'), //已选合计
105
+ list: this.config.map(c => ({
106
+ label: c.label,
107
+ value: (() => {
108
+ if (c.label === this.$l('条数')) {
109
+ //笔|条 数
110
+ return coins.length
111
+ }
112
+ return coins.reduce((amount, item) => amount + item[c.key], 0)
113
+ })()
114
+ }))
115
+ }
116
+ ]
117
+ this.selectStatistics.push({...statistic, statis})
118
+ }
119
+ })
120
+ },
121
+ uniqueByAccountNo(arr) {
122
+ return arr.reduce((acc, current) => {
123
+ const exists = acc.some(item => item.accountNo === current.accountNo);
124
+ if (!exists) {
125
+ acc.push(current);
126
+ }
127
+ return acc;
128
+ }, []);
129
+ },
130
+ /**
131
+ * 构造底部统计数据
132
+ */
133
+ generateStatistics() {
134
+ this.selectTotal = 0
135
+ if (!this.views.length) {
136
+ this.allStatistics = [{
137
+ title: this.$l('人民币'),
138
+ statis: [
139
+ {
140
+ type: this.$l('全部合计'),
141
+ list: this.config.map(c => ({label: c.label, value: 0}))
142
+ }
143
+ ]
144
+ }]
145
+ this.selectStatistics = [{
146
+ title: this.$l('人民币'),
147
+ statis: [
148
+ {
149
+ type: this.$l('已选合计'),
150
+ list: this.config.map(c => ({label: c.label, value: 0}))
151
+ }
152
+ ]
153
+ }]
154
+ this.selectStatisticsTpl = [{
155
+ title: this.$l('人民币'),
156
+ statis: [
157
+ {
158
+ type: this.$l('已选合计'),
159
+ list: this.config.map(c => ({label: c.label, value: 0}))
160
+ }
161
+ ]
162
+ }]
163
+ return
164
+ }
165
+ const allStatistics = []
166
+ const selectedStatistics = []
167
+ this.views.forEach(item => {
168
+ allStatistics.push({
169
+ title: item.currencyName,
170
+ currencyNo: item.currencyNo,
171
+ statis: [
172
+ {
173
+ type: this.$l('全部合计'), //全部合计
174
+ list: this.config.map(c => ({label: c.label, value: item[c.code] || '0'}))
175
+ }
176
+ ]
177
+ })
178
+ selectedStatistics.push({
179
+ title: item.currencyName,
180
+ currencyNo: item.currencyNo,
181
+ statis: [
182
+ {
183
+ type: this.$l('已选合计'), //已选合计
184
+ list: this.config.map(c => ({label: c.label, value: 0}))
185
+ }
186
+ ]
187
+ })
188
+ })
189
+ this.allStatistics = this.sortCurrencyToFront(allStatistics)
190
+ this.selectStatisticsTpl = this.sortCurrencyToFront(selectedStatistics)
191
+ this.selectStatistics = [this.sortCurrencyToFront(selectedStatistics)[0]]
192
+ // 回调一次计算已选合计的过程,处理一个接口导致的全部合计再次刷新的问题
193
+ this.$nextTick(()=>{
194
+ this.calculationSelected()
195
+ })
196
+ },
197
+ sortCurrencyToFront(data) {
198
+ let currencyNo = 'CNY'
199
+ if (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.defaultCurrencyNo) {
200
+ currencyNo = this.$store.state.user.defaultCurrencyNo
201
+ }
202
+ // 创建一个新数组以避免修改原数组
203
+ const newArray = [...data];
204
+
205
+ // 查找匹配的货币索引
206
+ const index = newArray.findIndex(item =>
207
+ item.currencyNo && item.currencyNo.trim().toUpperCase() === currencyNo.trim().toUpperCase()
208
+ );
209
+
210
+ // 如果找到匹配项
211
+ if (index > -1) {
212
+ // 从数组中移除匹配项
213
+ const [matchedItem] = newArray.splice(index, 1);
214
+ // 将匹配项添加到数组开头
215
+ newArray.unshift(matchedItem);
216
+ }
217
+
218
+ return newArray;
219
+ }
220
+ }
221
+ }
222
+ </script>
223
+
224
+ <style scoped lang="scss">
225
+ .footer-static{
226
+ flex: 1;
227
+ flex-wrap: wrap;
228
+ }
229
+ </style>
@@ -0,0 +1,21 @@
1
+ // import request from '@/utils/request'
2
+
3
+ // 单位本位币
4
+ export function getUnitCurrency(unitNo) {
5
+ // return request({
6
+ // url: `/api/bems/1.0/unit/${unitNo}`,
7
+ // method: 'get',
8
+ // loading: false
9
+ // })
10
+ }
11
+
12
+ // 币种
13
+ export function getCurrency(data, headers = {}) {
14
+ // return request({
15
+ // url: '/api/nstc-mdm/1.0/currency',
16
+ // method: 'get',
17
+ // params: data,
18
+ // loading: false,
19
+ // headers
20
+ // })
21
+ }
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import fitlers from './filters/index'
3
3
  import repairEl from './utils/repairElementUI'
4
4
  import { getColumnWidth, getCellAlign } from './utils/tableCellUtils'
5
+ import { getExportFileName } from './utils/exportFile'
5
6
  // 导入组件
6
7
  import MainPage from '../packages/main-page/index.js'
7
8
  import TablePage from '../packages/table-page/index.js'
@@ -10,6 +11,7 @@ import TabPane from '../packages/tab-pane/index.js'
10
11
  import StatisCard from '../packages/statis-card/index.js'
11
12
  import PageHeader from '../packages/page-header/index.js'
12
13
  import CommonCollapse from '../packages/common-collapse/index.js'
14
+ import MultiCurrencyStatistics from '../packages/multi-currency-statistics/index.js'
13
15
 
14
16
  // 存储组件列表
15
17
  const components = [
@@ -19,7 +21,8 @@ const components = [
19
21
  TabPane,
20
22
  StatisCard,
21
23
  CommonCollapse,
22
- PageHeader
24
+ PageHeader,
25
+ MultiCurrencyStatistics
23
26
  ]
24
27
 
25
28
  // 定义 install 方法,接收 Vue 作为参数
@@ -55,7 +58,9 @@ export {
55
58
  CommonCollapse,
56
59
  TabPane,
57
60
  PageHeader,
61
+ MultiCurrencyStatistics,
58
62
  repairEl,
59
63
  getColumnWidth,
60
- getCellAlign
64
+ getCellAlign,
65
+ getExportFileName
61
66
  }
@@ -0,0 +1,25 @@
1
+ import Vue from 'vue'
2
+ import Vuex from 'vuex'
3
+ import getters from './getters'
4
+
5
+ Vue.use(Vuex)
6
+
7
+ // https://webpack.js.org/guides/dependency-management/#requirecontext
8
+ const modulesFiles = require.context('./modules', true, /\.js$/)
9
+
10
+ // you do not need `import app from './modules/app'`
11
+ // it will auto require all vuex module from modules file
12
+ const modules = modulesFiles.keys().reduce((modules, modulePath) => {
13
+ // set './app.js' => 'app'
14
+ const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
15
+ const value = modulesFiles(modulePath)
16
+ modules[moduleName] = value.default
17
+ return modules
18
+ }, {})
19
+
20
+ const store = new Vuex.Store({
21
+ modules,
22
+ getters
23
+ })
24
+
25
+ export default store
@@ -0,0 +1,42 @@
1
+ import { getUnitCurrency, getCurrency } from '@/api/common.js'
2
+
3
+ const state = {
4
+ defaultCurrencyNo: '',
5
+ defaultCurrencyName: ''
6
+ }
7
+
8
+ const mutations = {
9
+ SET_DEFAULTCURRENCYNO: (state, currencyNo) => {
10
+ state.defaultCurrencyNo = currencyNo
11
+ },
12
+ SET_DEFAULTCURRENCYNAME: (state, currencyName) => {
13
+ state.defaultCurrencyName = currencyName
14
+ }
15
+ }
16
+
17
+ const actions = {
18
+ async getDefaultCurrency({commit}) {
19
+ const userInfo = JSON.parse(sessionStorage.getItem('User_Info'))
20
+ // const resUnit = await getUnitCurrency(userInfo.custNo) //归集主体
21
+ // if (resUnit.currencyNo) {
22
+ // console.log("🚀 ~ getDefaultCurrency ~ resUnit.currencyNo:", resUnit.currencyNo)
23
+ // commit('SET_DEFAULTCURRENCYNO', resUnit.currencyNo)
24
+ // commit('SET_DEFAULTCURRENCYNAME', resUnit.currencyName)
25
+ // } else {
26
+ // const list = await getCurrency({ isEnable: 1 }, false)
27
+ // const allCurrency = list.find(item => item.currencyType === 0)
28
+ // if (allCurrency) {
29
+ // commit('SET_DEFAULTCURRENCYNO', allCurrency.currencyNo)
30
+ // commit('SET_DEFAULTCURRENCYNAME', allCurrency.currencyName)
31
+ // }
32
+ // }
33
+
34
+ }
35
+ }
36
+
37
+ export default {
38
+ namespaced: true,
39
+ state,
40
+ mutations,
41
+ actions
42
+ }
@@ -0,0 +1,12 @@
1
+ export function generateUUID() {
2
+ let d = new Date().getTime();
3
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
4
+ d += performance.now(); //use high-precision timer if available
5
+ }
6
+ const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
7
+ const r = (d + Math.random()*16)%16 | 0;
8
+ d = Math.floor(d/16);
9
+ return (c=='x' ? r : (r&0x3|0x8)).toString(16);
10
+ });
11
+ return uuid;
12
+ }
@@ -0,0 +1,44 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ // 日期格式化
4
+ export function parseDate(date, format) {
5
+ var o = {
6
+ "M+": date.getMonth() + 1,
7
+ "d+": date.getDate(),
8
+ "h+": date.getHours(),
9
+ "m+": date.getMinutes(),
10
+ "s+": date.getSeconds(),
11
+ "q+": Math.floor((date.getMonth() + 3) / 3),
12
+ S: date.getMilliseconds()
13
+ };
14
+ let yearReg = format.match(/(y+)/i);
15
+ if (yearReg) {
16
+ let year = date.getFullYear() + "";
17
+ year = year.substring(4 - yearReg[0].length);
18
+ format = format.replace(yearReg[0], year);
19
+ }
20
+ for (var k in o) {
21
+ let iReg = format.match(new RegExp("(" + k + ")"));
22
+ if (iReg) {
23
+ format = format.replace(iReg[0], iReg[0].length == 1 ? o[k] : ("00" + o[k]).substring(("" + o[k]).length));
24
+ }
25
+ }
26
+ return format;
27
+ }
28
+
29
+
30
+ /**
31
+ * 获取本月第一天
32
+ * @returns {string} e.g. '2025-10-01'
33
+ */
34
+ export function getFirstDayOfThisMonth() {
35
+ return dayjs().startOf('month').format('YYYY-MM-DD');
36
+ }
37
+
38
+ /**
39
+ * 获取当前日期
40
+ * @returns {string} e.g. '2025-10-17'
41
+ */
42
+ export function getCurrentDate() {
43
+ return dayjs().format('YYYY-MM-DD');
44
+ }
@@ -0,0 +1,7 @@
1
+ import { parseDate } from './date.js';
2
+
3
+ // 获取导出文件命名
4
+ export function getExportFileName(baseName, fileType) {
5
+ const date = parseDate(new Date(), "yyyyMMdd");
6
+ return `${baseName}-${date}.${fileType}`;
7
+ }