@94ai/nf-double-quarter 3.1.36 → 3.1.38

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.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 季节对应筛选项
3
+ */
4
+ export const quarterOptions = [
5
+ {
6
+ label: 'Q1',
7
+ value: 1,
8
+ months: [1, 2, 3]
9
+ },
10
+ {
11
+ label: 'Q2',
12
+ value: 2,
13
+ months: [4, 5, 6]
14
+ },
15
+ {
16
+ label: 'Q3',
17
+ value: 3,
18
+ months: [7, 8, 9]
19
+ },
20
+ {
21
+ label: 'Q4',
22
+ value: 4,
23
+ months: [10, 11, 12]
24
+ }
25
+ ];
26
+
27
+ /**
28
+ * 获取季度对应的月份
29
+ * @returns
30
+ */
31
+ export function getQuarterOptionMonths(value) {
32
+ for (let item of quarterOptions) {
33
+ if (item.value == value) {
34
+ return item.months;
35
+ }
36
+ }
37
+ return []
38
+ }
39
+
40
+ /**
41
+ * 获取日期对应季度
42
+ * @returns
43
+ */
44
+ export function getQuarterItemOfMonth(month) {
45
+ for (let item of quarterOptions) {
46
+ if (item.months.includes(month)) {
47
+ return item;
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,8 @@
1
+ import NfDoubleQuarter from './nf-double-quarter.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+
4
+ NfDoubleQuarter.install = (app: typeof Vue2) => {
5
+ app!.component('nf-double-quarter', NfDoubleQuarter)
6
+ }
7
+
8
+ export default NfDoubleQuarter as typeof NfDoubleQuarter & PluginObject<undefined>
@@ -0,0 +1,256 @@
1
+ <template>
2
+ <el-popover
3
+ class="nf-double-quarter nf-quarter-range-picker"
4
+ v-model="nfDoubleQuatterPopoverVisible"
5
+ :placement="placement"
6
+ :transition="transition"
7
+ :disabled="disabled"
8
+ :offset="offset"
9
+ :popper-class="(popperClass || '') + ' nf-double-quarter nf-quarter-range-picker'"
10
+ :trigger="trigger"
11
+ :visible-arrow="visibleArrow"
12
+ :popper-options="popperOptions"
13
+ :open-delay="openDelay"
14
+ :close-delay="closeDelay"
15
+ :tabindex="tabindex"
16
+ @show="$emit('show')"
17
+ @after-enter="$emit('after-enter')"
18
+ @hide="$emit('hide')"
19
+ @after-leave="$emit('after-leave')"
20
+ :append-to-body="appendToBody"
21
+ >
22
+ <el-date-picker slot="reference"
23
+ popper-class="nf-double-quarter nf-quarter-range-picker-el-date-picker"
24
+ type="monthrange"
25
+ @focus="handleOpenPicker"
26
+ @change="handleChange"
27
+ @blur="$emit('blur', $event)"
28
+ :validate-event="false"
29
+ :value="showValue"
30
+ :disabled="disabled"
31
+ :format="format"
32
+ :readonly="readonly"
33
+ :range-separator="rangeSeparator"
34
+ :clear-icon="clearIcon"
35
+ :prefix-icon="prefixIcon"
36
+ :clearable="clearable"
37
+ :size="size"
38
+ :start-placeholder="startPlaceholder"
39
+ :end-placeholder="endPlaceholder" />
40
+ <div class="nf-quarter-range-picker__content">
41
+ <quarter-picker-item :year.sync="startYear"
42
+ :quarter="startQuarter"
43
+ :showRight="false"
44
+ @on-quarter-click="handleStartQuarterClick"
45
+ @on-year-change="handleStartYearChange"></quarter-picker-item>
46
+ <quarter-picker-item :year.sync="endYear"
47
+ :showLeft="false"
48
+ :quarter.sync="endQuarter"
49
+ @on-quarter-click="handleEndQuarterClick"
50
+ @on-year-change="handleEndYearChange"></quarter-picker-item>
51
+ </div>
52
+ </el-popover>
53
+ </template>
54
+
55
+ <script lang="ts">
56
+ import {
57
+ defineComponent,
58
+ } from 'vue-demi'
59
+
60
+ export default defineComponent({
61
+ name: 'NfDoubleQuarter',
62
+ })
63
+ </script>
64
+ <script setup lang="ts">
65
+ import QuarterPickerItem from './nf-quarter-picker-item.vue'
66
+ import {
67
+ ref,
68
+ defineProps,
69
+ defineEmits,
70
+ computed,
71
+ } from 'vue-demi'
72
+ import {
73
+ endOf,
74
+ formatDate,
75
+ getNextYear,
76
+ getQuarter,
77
+ startOf
78
+ } from './util'
79
+ import { getQuarterOptionMonths } from './config'
80
+ import { QuarterItem } from './types'
81
+
82
+ const props = withDefaults(defineProps<{
83
+ // [起始日期,结束日期]
84
+ value?: string[],
85
+ size?: 'mini' | 'small' | 'medium' | 'large',
86
+ rangeSeparator?: string,
87
+ readonly?: boolean,
88
+ clearable?: boolean,
89
+ startPlaceholder?: string,
90
+ endPlaceholder?: string,
91
+ format?: string,
92
+ disabled?: boolean,
93
+ prefixIcon?: string,
94
+ clearIcon?: string,
95
+ transition?: string,
96
+ placement?: string,
97
+ popperClass?: string,
98
+ trigger?: string,
99
+ offset?: number,
100
+ visibleArrow?: boolean,
101
+ popperOptions?: Object,
102
+ openDelay?: number,
103
+ closeDelay?: number,
104
+ tabindex?: number,
105
+ appendToBody?: boolean
106
+ }>(), {
107
+ // [起始日期,结束日期]
108
+ value: undefined,
109
+ size: 'mini',
110
+ rangeSeparator: '-',
111
+ readonly: false,
112
+ clearable: true,
113
+ startPlaceholder: '开始季度',
114
+ endPlaceholder: '结束季度',
115
+ format: 'yyyy-QM',
116
+ disabled: false,
117
+ offset: 0,
118
+ prefixIcon: 'el-icon-date',
119
+ clearIcon: 'el-icon-circle-close',
120
+ transition: 'el-zoom-in-top',
121
+ placement: 'bottom-start',
122
+ popperClass: '',
123
+ trigger: 'click',
124
+ visibleArrow: true,
125
+ openDelay: undefined,
126
+ closeDelay: 200,
127
+ tabindex: 0,
128
+ appendToBody: true,
129
+ popperOptions: () => ({ boundariesElement: 'body', gpuAcceleration: false }),
130
+ })
131
+
132
+ const emits = defineEmits<{
133
+ (e: 'update:value', val: string[] | null): void,
134
+ (e: 'input', val: string[] | null): void,
135
+ (e: 'change', value: (QuarterItem & { startDate: string, endDate: string})[]): void
136
+ (e: 'show', value:undefined): void
137
+ (e: 'after-enter', value:undefined): void
138
+ (e: 'hide', value: undefined): void
139
+ (e: 'after-leave', value:undefined): void
140
+ (e: 'blur', value: any ): void
141
+ (e: 'focus', value: any): void
142
+ }>()
143
+
144
+ const now = new Date()
145
+ const nfDoubleQuatterPopoverVisible = ref(false)
146
+ // 开始
147
+ const startYear = ref(now.getFullYear())
148
+ const startQuarter = ref<string[]>([])
149
+ // 结束
150
+ const endYear = ref(now.getFullYear() + 1)
151
+ const endQuarter = ref<string[]>([])
152
+ // 整合后的月份
153
+ const quarter = ref<QuarterItem[]>([])
154
+
155
+ const showValue = computed(() => {
156
+ if (props.value) {
157
+ const startDate = new Date(props.value[0])
158
+ const endDate = new Date(props.value[1])
159
+ return [`${startDate.getFullYear()}-${getQuarter(startDate)}`, `${endDate.getFullYear()}-${getQuarter(endDate)}`]
160
+ }
161
+ return null
162
+ })
163
+
164
+ const handleOpenPicker = (instance) => {
165
+ let startDate = new Date()
166
+ let endDate = getNextYear(startDate)
167
+ if (props.value) {
168
+ startDate = new Date(props.value[0])
169
+ endDate = new Date(props.value[1])
170
+ startQuarter.value = [`${startDate.getFullYear()}-${getQuarter(startDate)}`]
171
+ endQuarter.value = [`${endDate.getFullYear()}-${getQuarter(endDate)}`]
172
+ }
173
+
174
+ startYear.value = startDate.getFullYear()
175
+ // 结束
176
+ endYear.value = endDate.getFullYear()
177
+ if (startYear.value >= endYear.value) {
178
+ endYear.value = startYear.value + 1
179
+ }
180
+ // 清空已选中
181
+ quarter.value.splice(0, quarter.value.length)
182
+ emits('focus', instance)
183
+ }
184
+ const handleStartYearChange = (year) => {
185
+ endYear.value = year + 1
186
+ }
187
+ const handleStartQuarterClick = (quarterItem: QuarterItem) => {
188
+ if (quarter.value.length == 0) {
189
+ startQuarter.value.splice(0, startQuarter.value.length)
190
+ endQuarter.value.splice(0, endQuarter.value.length)
191
+ }
192
+
193
+ const index = startQuarter.value.indexOf(quarterItem.value)
194
+ if (index > -1) {
195
+ startQuarter.value.splice(index, 1)
196
+ } else {
197
+ startQuarter.value.push(quarterItem.value)
198
+ }
199
+
200
+ quarter.value.push(quarterItem)
201
+
202
+ handleCheckQuarterRange()
203
+ }
204
+ const handleEndQuarterClick = (quarterItem: QuarterItem) => {
205
+ if (quarter.value.length == 0) {
206
+ startQuarter.value.splice(0, startQuarter.value.length)
207
+ endQuarter.value.splice(0, endQuarter.value.length)
208
+ }
209
+ const index = endQuarter.value.indexOf(quarterItem.value)
210
+ if (index > -1) {
211
+ endQuarter.value.splice(index, 1)
212
+ } else {
213
+ endQuarter.value.push(quarterItem.value)
214
+ }
215
+ quarter.value.push(quarterItem)
216
+ handleCheckQuarterRange()
217
+ }
218
+ const handleCheckQuarterRange = () => {
219
+ if (quarter.value.length == 2) {
220
+ // 排序
221
+ quarter.value.sort((a, b) => {
222
+ if (a.year == b.year) {
223
+ return a.quarter - b.quarter
224
+ } else {
225
+ return a.year - b.year
226
+ }
227
+ })
228
+ const result: (QuarterItem & { startDate: string, endDate: string})[] = []
229
+ for (let item of quarter.value) {
230
+ const months = getQuarterOptionMonths(item.quarter)
231
+ if(months.length) {
232
+ result.push({
233
+ ...item,
234
+ startDate: formatDate(startOf(new Date(item.year, months[0] - 1), 'month'), 'YYYY-MM-DD'),
235
+ endDate: formatDate(endOf(new Date(item.year, months[months.length - 1] - 1), 'month'), 'YYYY-MM-DD')
236
+ })
237
+ }
238
+ }
239
+ emits('update:value', [result[0].startDate, result[1].endDate])
240
+ emits('input', [result[0].startDate, result[1].endDate])
241
+ emits('change', result)
242
+ nfDoubleQuatterPopoverVisible.value = false
243
+ }
244
+ }
245
+ const handleEndYearChange = () => {
246
+ startYear.value = endYear.value - 1
247
+ }
248
+ const handleChange = (val) => {
249
+ if (!val) {
250
+ startQuarter.value.splice(0, startQuarter.value.length)
251
+ endQuarter.value.splice(0, endQuarter.value.length)
252
+ emits('update:value', null)
253
+ emits('input', null)
254
+ }
255
+ }
256
+ </script>
@@ -0,0 +1,108 @@
1
+ <template>
2
+ <div class="nf-double-quarter nf-quarter-picker-item">
3
+ <div class="nf-quarter-picker__header">
4
+ <i class="el-icon-d-arrow-left"
5
+ @click="handlePrevYear"
6
+ v-if="showLeft"></i>
7
+ <span v-else
8
+ class="empty-arrow"></span>
9
+ <div class="nf-quarter-picker__title">{{ year }}</div>
10
+ <i class="el-icon-d-arrow-right"
11
+ @click="handleNextYear"
12
+ v-if="showRight"></i>
13
+ <span v-else
14
+ class="empty-arrow"></span>
15
+ </div>
16
+ <div class="nf-quarter-picker__options">
17
+ <template v-for="item in options">
18
+ <div class="nf-quarter-picker__item"
19
+ v-bind:key="item.value"
20
+ :data-value="item.value"
21
+ @click="handleItemClick(item)"
22
+ :class="{
23
+ 'nf-quarter-picker__item__today': item.value == now_quarter,
24
+ 'nf-quarter-picker__item--active': quarter.includes(item.value),
25
+ }">
26
+ <div class="nf-quarter-picker__item__label">{{ item.label }}</div>
27
+ </div>
28
+ </template>
29
+ </div>
30
+ </div>
31
+ </template>
32
+
33
+ <script lang="ts">
34
+ import { defineComponent } from 'vue-demi'
35
+
36
+ export default defineComponent({
37
+ name: 'nf-quarter-picker-item',
38
+ })
39
+ </script>
40
+ <script setup lang="ts">
41
+ import {
42
+ computed,
43
+ defineEmits,
44
+ defineProps,
45
+ ref
46
+ } from 'vue-demi'
47
+ import { getQuarter } from './util'
48
+ import { quarterOptions } from './config'
49
+ import { QuarterItem } from './types'
50
+
51
+ const props = withDefaults(defineProps<{
52
+ // 当前年
53
+ year?: number,
54
+ // 当前季度
55
+ quarter?: string[],
56
+ // 显示左边按钮
57
+ showLeft?: boolean,
58
+ // 显示右边按钮
59
+ showRight?: boolean
60
+ }>(), {
61
+ // 当前年
62
+ year: new Date().getFullYear(),
63
+ // 当前季度
64
+ quarter: () => { return [] },
65
+ // 显示左边按钮
66
+ showLeft: true,
67
+ // 显示右边按钮
68
+ showRight: true
69
+ })
70
+
71
+
72
+ const emits = defineEmits<{
73
+ (e: 'on-quarter-click', val: QuarterItem): void,
74
+ (e: 'update:year', value: number): void
75
+ (e: 'on-year-change', value: number): void
76
+ }>()
77
+ const now = new Date();
78
+ const now_year = ref(now.getFullYear());
79
+ const now_quarter = `${now_year.value}-${getQuarter(now)}`
80
+ const options = computed(() => {
81
+ return quarterOptions.map(item => {
82
+ return {
83
+ label: item.label,
84
+ value: `${props.year}-${item.value}`,
85
+ year: props.year,
86
+ quarter: item.value,
87
+ }
88
+ })
89
+ })
90
+
91
+
92
+ const handleItemClick = (item) => {
93
+ emits('on-quarter-click', item);
94
+ }
95
+
96
+ const handlePrevYear = () => {
97
+ const year = props.year - 1;
98
+ emits('update:year', year);
99
+ emits('on-year-change', year);
100
+ }
101
+
102
+ const handleNextYear = () => {
103
+ const year = props.year + 1;
104
+ emits('update:year', year);
105
+ emits('on-year-change', year);
106
+ }
107
+ </script>
108
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-double-quarter.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-double-quarter.scss'
@@ -0,0 +1,6 @@
1
+ export interface QuarterItem {
2
+ label: 'Q1' | 'Q2' | 'Q3' | 'Q4',
3
+ value: string,
4
+ year: number,
5
+ quarter: 1 | 2 | 3 | 4,
6
+ }
@@ -0,0 +1,56 @@
1
+ export function getQuarter(date = new Date()) {
2
+ const currMonth = date.getMonth() + 1
3
+ return Math.floor((currMonth % 3 == 0 ? (currMonth / 3) : (currMonth / 3 + 1)))
4
+ }
5
+ export function getNextYear(date = new Date()) {
6
+ return new Date(date.setFullYear(date.getFullYear() + 1))
7
+ }
8
+ export function endOf(now = new Date(), unit) {
9
+ if (unit === 'year') {
10
+ return new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
11
+ }
12
+ if (unit === 'month') {
13
+ return new Date(new Date(now.getFullYear(), now.getMonth() + 1, 1).getTime() - 1);
14
+ }
15
+ if (unit === 'week') {
16
+ return new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - now.getDay()), 23, 59, 59, 999);
17
+ }
18
+ return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
19
+ }
20
+
21
+ export function startOf(date, unit) {
22
+ const newDate = new Date(date)
23
+ if (unit === 'year') {
24
+ newDate.setMonth(0)
25
+ newDate.setDate(1)
26
+ newDate.setHours(0, 0, 0, 0)
27
+ } else if (unit === 'month') {
28
+ newDate.setDate(1)
29
+ newDate.setHours(0, 0, 0, 0)
30
+ } else if (unit === '') {
31
+ newDate.setHours(0, 0, 0, 0)
32
+ } else if (unit === 'hour') {
33
+ newDate.setMinutes(0, 0, 0)
34
+ } else if (unit === 'minute') {
35
+ newDate.setSeconds(0, 0)
36
+ } else if (unit === 'second') {
37
+ newDate.setMilliseconds(0)
38
+ }
39
+ return newDate
40
+ }
41
+
42
+ export function formatDate(date, format) {
43
+ const year = date.getFullYear()
44
+ const month = date.getMonth() + 1
45
+ const day = date.getDate()
46
+ const hours = date.getHours()
47
+ const minutes = date.getMinutes()
48
+ const seconds = date.getSeconds()
49
+ format = format.replace('YYYY', year)
50
+ format = format.replace('MM', String(month).padStart(2, '0'))
51
+ format = format.replace('DD', String(day).padStart(2, '0'))
52
+ format = format.replace('HH', String(hours).padStart(2, '0'))
53
+ format = format.replace('mm', String(minutes).padStart(2, '0'))
54
+ format = format.replace('ss', String(seconds).padStart(2, '0'))
55
+ return format
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-double-quarter",
3
- "version": "3.1.36",
3
+ "version": "3.1.38",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.1.36",
17
+ "@94ai/nf-theme-chalk": "^1.0.0",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-double-quarter.cjs.js",
32
32
  "module": "lib/nf-double-quarter.esm-bundler.js",
33
- "gitHead": "c95b0b2f85a3ec95a21f8a2448113370e6b826d8"
33
+ "gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
34
34
  }