shijiplus-web-plugin 0.1.24 → 0.1.26

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": "shijiplus-web-plugin",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "files": [
5
5
  "src"
6
6
  ],
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  import PlusCircleProgressModal from './plus-circle-progress-modal.vue'
2
3
  export default {
3
4
  data() {
@@ -8,74 +9,161 @@ export default {
8
9
  }
9
10
  },
10
11
  methods: {
11
- invokeExportExcel(searchForm, apiFunction, options = {}) {
12
- const { exportDesc } = this.$merge({}, options)
13
- const checkExportDataTotal = (searchForm) => {
14
- return apiFunction({
12
+ // Helper function to generate a list of 4-hour intervals between startDate and endDate
13
+ getDateRange(startDate, endDate) {
14
+ const intervals = []
15
+ let currentDate = new Date(startDate)
16
+ const end = new Date(endDate)
17
+
18
+ while (currentDate <= end) {
19
+ const nextDate = new Date(currentDate)
20
+ nextDate.setHours(currentDate.getHours() + 4)
21
+ intervals.push({
22
+ start: new Date(currentDate),
23
+ end: nextDate > end ? new Date(end) : nextDate
24
+ })
25
+ currentDate = nextDate
26
+ }
27
+ return intervals
28
+ },
29
+
30
+ // Helper function to delay for a while
31
+ delay() {
32
+ return new Promise(resolve => setTimeout(resolve, 100))
33
+ },
34
+
35
+ // Format date to 'yyyy-MM-dd HH:mm:ss'
36
+ formatDate(date) {
37
+ const pad = (num) => (num < 10 ? '0' + num : num)
38
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
39
+ },
40
+
41
+ // Function to fetch data for a specific 4-hour interval
42
+ async fetchDataForInterval(interval, searchForm, apiFunction) {
43
+ const intervalStart = this.formatDate(interval.start)
44
+ const intervalEnd = this.formatDate(interval.end)
45
+
46
+ // Query the total count for this interval
47
+ const intervalSearchForm = {
48
+ ...searchForm,
49
+ startDate: intervalStart,
50
+ endDate: intervalEnd,
51
+ pageNo: 1,
52
+ currentPage: 1,
53
+ pageSize: 1
54
+ }
55
+ await this.delay()
56
+ const res = await apiFunction(intervalSearchForm)
57
+ const intervalTotalCount = res.meta ? res.meta.totalCount : (res.data || []).length
58
+
59
+ let intervalData = []
60
+ if (intervalTotalCount <= this.orderExportPageSize) {
61
+ // Fetch all data for the interval in one request
62
+ await this.delay()
63
+ const fetchRes = await apiFunction({
15
64
  ...searchForm,
65
+ startDate: intervalStart,
66
+ endDate: intervalEnd,
16
67
  pageNo: 1,
17
68
  currentPage: 1,
18
- pageSize: 1
69
+ pageSize: intervalTotalCount
19
70
  })
20
- .then((res) => {
21
- if (res && res.meta) {
22
- this.totalCount = res.meta.totalCount
23
- } else {
24
- this.totalCount = (res.data || []).length
25
- }
71
+ intervalData = fetchRes.data || []
72
+ } else {
73
+ // Fetch data in batches (pagination)
74
+ const totalPages = Math.ceil(intervalTotalCount / this.orderExportPageSize)
75
+ for (let page = 1; page <= totalPages; page++) {
76
+ await this.delay()
77
+ const fetchRes = await apiFunction({
78
+ ...searchForm,
79
+ startDate: intervalStart,
80
+ endDate: intervalEnd,
81
+ pageNo: page,
82
+ currentPage: page,
83
+ pageSize: this.orderExportPageSize
26
84
  })
85
+ intervalData.push(...(fetchRes.data || []))
86
+ }
27
87
  }
28
- let exportData = []
29
- const excelExportFun = (pageNo, pageSize, processUpdate) => {
30
- return apiFunction({
31
- ...searchForm,
32
- currentPage: pageNo,
33
- pageNo: pageNo,
34
- pageSize: pageSize
35
- }).then((res) => {
36
- if (res && res.data) {
37
- exportData.push(...res.data)
38
- } else {
39
- throw Error('导出失败')
40
- }
41
- this.orderExportModalPercent = (exportData.length / (this.totalCount || 1) * 100).toFixed(2)
42
- if (processUpdate) {
43
- processUpdate(this.orderExportModalPercent)
44
- }
45
- if (exportData.length < this.totalCount) {
46
- return excelExportFun(pageNo + 1, pageSize, processUpdate)
47
- }
48
- return exportData
49
- }).catch((error) => {
50
- console.log('--------error---------', error)
51
- throw Error('导出失败')
52
- })
53
- }
54
- return checkExportDataTotal(searchForm).then((res) => {
88
+ return { intervalData, intervalTotalCount }
89
+ },
90
+
91
+ // Main export function
92
+ async invokeExportExcel(searchForm, apiFunction) {
93
+ try {
94
+ // 0. Validate the date range (limit to 1 month)
95
+ const startDate = new Date(searchForm.startDate || searchForm.startTime)
96
+ const endDate = new Date(searchForm.endDate || searchForm.startTime)
97
+ const oneMonthInMs = 31 * 24 * 60 * 60 * 1000 // 1 个月的毫秒数
98
+
99
+ if (endDate - startDate > oneMonthInMs) {
100
+ setTimeout(() => {
101
+ this.$Message.error('导出时间范围不能超过1个月,请调整后重试', 3)
102
+ }, 0)
103
+ return
104
+ }
105
+
106
+ // 1. Query the total count for the entire task
107
+ const checkExportDataTotal = async (searchForm) => {
108
+ await this.delay()
109
+ const res = await apiFunction({
110
+ ...searchForm,
111
+ pageNo: 1,
112
+ currentPage: 1,
113
+ pageSize: 1
114
+ })
115
+ this.totalCount = res.meta ? res.meta.totalCount : (res.data || []).length
116
+ }
117
+ await checkExportDataTotal(searchForm)
118
+
55
119
  if (this.totalCount === 0) {
56
- // 宏任务最后执行
57
120
  setTimeout(() => {
58
121
  this.$Message.error('暂无数据,请搜索后重试', 3)
59
122
  }, 0)
60
123
  return
61
124
  }
62
- const processInstance = this.$getComponentInstance(PlusCircleProgressModal)
63
- processInstance.$on('on-close', (e) => {
125
+
126
+ // 2. Get the 4-hour intervals from startDate to endDate
127
+ const intervals = this.getDateRange(startDate, endDate)
128
+
129
+ // 3. Initialize the progress modal
130
+ const instance = this.$getComponentInstance(PlusCircleProgressModal)
131
+ instance.$on('on-close', () => {
64
132
  setTimeout(() => {
65
- this.$removeVComp(processInstance)
133
+ this.$removeVComp(instance)
66
134
  }, 500)
67
135
  })
68
- processInstance.show({ exportDesc })
69
- return excelExportFun(1, this.orderExportPageSize, (process) => {
70
- processInstance.updatePercent(process)
71
- }).catch(() => {
72
- // 宏任务最后执行
73
- setTimeout(() => {
74
- this.$Message.error('导出失败', 3)
75
- this.$removeVComp(processInstance)
76
- }, 0)
77
- })
78
- })
136
+ instance.show()
137
+
138
+ // 4. Fetch data interval by interval and update progress
139
+ let exportedCount = 0
140
+ let exportData = []
141
+ for (const interval of intervals) {
142
+ const { intervalData, intervalTotalCount } = await this.fetchDataForInterval(interval, searchForm, apiFunction)
143
+ exportData.push(...intervalData)
144
+ exportedCount += intervalData.length
145
+
146
+ // Update progress based on total count
147
+ this.orderExportModalPercent = (exportedCount / this.totalCount * 100).toFixed(2)
148
+ instance.updatePercent(this.orderExportModalPercent)
149
+ }
150
+
151
+ // 5. Export the data (logic omitted here, add your export implementation)
152
+ // console.log('Export data:', exportData)
153
+
154
+ return exportData
155
+
156
+ // 6. Close the progress modal
157
+ // instance.close()
158
+ } catch (error) {
159
+ console.error('导出失败:', error)
160
+ setTimeout(() => {
161
+ this.$Message.error('导出失败', 3)
162
+ if (instance) {
163
+ this.$removeVComp(instance)
164
+ }
165
+ }, 0)
166
+ }
79
167
  },
80
168
  exportAllData(searchForm, options = {}) {
81
169
  let exportData = []
@@ -1,6 +1,18 @@
1
1
  import Vue from 'vue'
2
+ import PlusConfirmModal from '../components/plus-comp/plus-confirm-modal/plus-confirm-modal'
2
3
  const install = (vue, opts = {}) => {
3
4
  console.log('------view--install------', opts)
5
+ vue.prototype.$PlusConfirmModal = {
6
+ show: (config) => {
7
+ const instance = vue.prototype.$getComponentInstance(PlusConfirmModal)
8
+ instance.$on('on-closed', (e) => {
9
+ setTimeout(() => {
10
+ vue.prototype.$removeVComp(instance)
11
+ }, 500)
12
+ })
13
+ return instance.show(config)
14
+ }
15
+ }
4
16
  const removeVComp = (vComp) => {
5
17
  if (vComp.$children && vComp.$children.length) {
6
18
  vComp.$children.forEach(item => {