vue2server7 7.0.107 → 7.0.109

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/test/1112 DELETED
@@ -1,69 +0,0 @@
1
- // public/config-worker.js
2
-
3
- let timer = null
4
- const KEY = 'APP_CONFIG_VERSION'
5
-
6
- function getVersion(text) {
7
- const match = text.match(/VERSION:\s*['"](.+?)['"]/)
8
- return match?.[1]
9
- }
10
-
11
- async function checkConfig() {
12
- const res = await fetch(`/config.js?t=${Date.now()}`, {
13
- cache: 'no-store'
14
- })
15
-
16
- const text = await res.text()
17
- const latestVersion = getVersion(text)
18
-
19
- if (!latestVersion) return
20
-
21
- postMessage({
22
- type: 'CONFIG_VERSION',
23
- version: latestVersion
24
- })
25
- }
26
-
27
- self.onmessage = (event) => {
28
- if (event.data?.type === 'START') {
29
- if (timer) return
30
-
31
- checkConfig()
32
-
33
- timer = setInterval(() => {
34
- checkConfig()
35
- }, event.data.interval || 10000)
36
- }
37
- }
38
-
39
-
40
- // src/utils/configWatcher.js
41
-
42
- const KEY = 'APP_CONFIG_VERSION'
43
-
44
- export function startConfigWatcher() {
45
- const worker = new Worker('/config-worker.js')
46
-
47
- worker.postMessage({
48
- type: 'START',
49
- interval: 10000
50
- })
51
-
52
- worker.onmessage = (event) => {
53
- const { type, version } = event.data || {}
54
-
55
- if (type !== 'CONFIG_VERSION' || !version) return
56
-
57
- const localVersion = localStorage.getItem(KEY)
58
-
59
- if (!localVersion) {
60
- localStorage.setItem(KEY, version)
61
- return
62
- }
63
-
64
- if (version !== localVersion) {
65
- localStorage.setItem(KEY, version)
66
- window.location.reload()
67
- }
68
- }
69
- }
package/test/11231231 DELETED
@@ -1,137 +0,0 @@
1
- <template>
2
- <el-dialog
3
- v-model="visible"
4
- title="切换机构"
5
- width="420px"
6
- :close-on-click-modal="false"
7
- >
8
- <el-form label-width="80px">
9
- <el-form-item label="机构">
10
- <el-select
11
- v-model="selectedOrgId"
12
- placeholder="请选择机构"
13
- style="width: 100%"
14
- filterable
15
- >
16
- <el-option
17
- v-for="item in orgList"
18
- :key="item.id"
19
- :label="item.name"
20
- :value="item.id"
21
- />
22
- </el-select>
23
- </el-form-item>
24
- </el-form>
25
-
26
- <template #footer>
27
- <el-button @click="handleCancel">取消</el-button>
28
- <el-button type="primary" @click="handleConfirm">
29
- 确定切换
30
- </el-button>
31
- </template>
32
- </el-dialog>
33
- </template>
34
-
35
- <script setup>
36
- import { ref, watch } from 'vue'
37
- import { ElMessage } from 'element-plus'
38
-
39
- const props = defineProps({
40
- modelValue: {
41
- type: Boolean,
42
- default: false
43
- },
44
- orgList: {
45
- type: Array,
46
- default: () => []
47
- },
48
- currentOrgId: {
49
- type: [String, Number],
50
- default: ''
51
- }
52
- })
53
-
54
- const emit = defineEmits([
55
- 'update:modelValue',
56
- 'confirm'
57
- ])
58
-
59
- const visible = ref(false)
60
- const selectedOrgId = ref('')
61
-
62
- watch(
63
- () => props.modelValue,
64
- val => {
65
- visible.value = val
66
- if (val) {
67
- selectedOrgId.value = props.currentOrgId
68
- }
69
- }
70
- )
71
-
72
- watch(visible, val => {
73
- emit('update:modelValue', val)
74
- })
75
-
76
- const handleCancel = () => {
77
- visible.value = false
78
- }
79
-
80
- const handleConfirm = () => {
81
- if (!selectedOrgId.value) {
82
- ElMessage.warning('请选择机构')
83
- return
84
- }
85
-
86
- emit('confirm', selectedOrgId.value)
87
- visible.value = false
88
- }
89
- </script>
90
- 、、、<template>
91
- <el-button type="primary" @click="showOrgDialog = true">
92
- 切换机构
93
- </el-button>
94
-
95
- <OrgSwitchDialog
96
- v-model="showOrgDialog"
97
- :org-list="orgList"
98
- :current-org-id="currentOrgId"
99
- @confirm="handleSwitchOrg"
100
- />
101
- </template>
102
-
103
- <script setup>
104
- import { ref } from 'vue'
105
- import { ElMessage } from 'element-plus'
106
- import OrgSwitchDialog from '@/components/OrgSwitchDialog.vue'
107
-
108
- const showOrgDialog = ref(false)
109
-
110
- const currentOrgId = ref(1)
111
-
112
- const orgList = ref([
113
- {
114
- id: 1,
115
- name: '总部机构'
116
- },
117
- {
118
- id: 2,
119
- name: '上海分公司'
120
- },
121
- {
122
- id: 3,
123
- name: '北京分公司'
124
- }
125
- ])
126
-
127
- const handleSwitchOrg = orgId => {
128
- currentOrgId.value = orgId
129
-
130
- const org = orgList.value.find(item => item.id === orgId)
131
-
132
- ElMessage.success(`已切换到:${org?.name || ''}`)
133
-
134
- // 这里可以调用接口
135
- // await switchOrgApi(orgId)
136
- }
137
- </script>
package/test/1312312 DELETED
@@ -1,164 +0,0 @@
1
- type WorkerMessage =
2
- | {
3
- type: 'START'
4
- interval?: number
5
- }
6
- | {
7
- type: 'CHECK_NOW'
8
- }
9
- | {
10
- type: 'STOP'
11
- }
12
-
13
- type WorkerResponse =
14
- | {
15
- type: 'CONFIG_VERSION'
16
- version: string
17
- }
18
- | {
19
- type: 'CONFIG_ERROR'
20
- message: string
21
- }
22
-
23
- let timer: ReturnType<typeof setInterval> | null = null
24
-
25
- function getVersion(text: string): string | null {
26
- const match = text.match(/VERSION:\s*['"](.+?)['"]/)
27
- return match?.[1] || null
28
- }
29
-
30
- async function checkConfig(): Promise<void> {
31
- try {
32
- const res = await fetch(`/config.js?t=${Date.now()}`, {
33
- cache: 'no-store'
34
- })
35
-
36
- const text = await res.text()
37
- const latestVersion = getVersion(text)
38
-
39
- if (!latestVersion) return
40
-
41
- const message: WorkerResponse = {
42
- type: 'CONFIG_VERSION',
43
- version: latestVersion
44
- }
45
-
46
- self.postMessage(message)
47
- } catch (err) {
48
- const message: WorkerResponse = {
49
- type: 'CONFIG_ERROR',
50
- message: err instanceof Error ? err.message : '配置检查失败'
51
- }
52
-
53
- self.postMessage(message)
54
- }
55
- }
56
-
57
- self.onmessage = (event: MessageEvent<WorkerMessage>) => {
58
- const data = event.data
59
-
60
- if (data.type === 'START') {
61
- if (timer) return
62
-
63
- checkConfig()
64
-
65
- timer = setInterval(() => {
66
- checkConfig()
67
- }, data.interval || 10000)
68
- }
69
-
70
- if (data.type === 'CHECK_NOW') {
71
- checkConfig()
72
- }
73
-
74
- if (data.type === 'STOP') {
75
- if (timer) {
76
- clearInterval(timer)
77
- timer = null
78
- }
79
- }
80
- }
81
-
82
- export {}
83
-
84
-
85
-
86
- type WorkerResponse =
87
- | {
88
- type: 'CONFIG_VERSION'
89
- version: string
90
- }
91
- | {
92
- type: 'CONFIG_ERROR'
93
- message: string
94
- }
95
-
96
- const CONFIG_VERSION_KEY = 'APP_CONFIG_VERSION'
97
-
98
- let worker: Worker | null = null
99
-
100
- function handleVersionChange(version: string): void {
101
- const localVersion = localStorage.getItem(CONFIG_VERSION_KEY)
102
-
103
- if (!localVersion) {
104
- localStorage.setItem(CONFIG_VERSION_KEY, version)
105
- return
106
- }
107
-
108
- if (version !== localVersion) {
109
- localStorage.setItem(CONFIG_VERSION_KEY, version)
110
- window.location.reload()
111
- }
112
- }
113
-
114
- export function startConfigWatcher(interval = 10000): void {
115
- if (worker) return
116
-
117
- worker = new Worker(new URL('../workers/config.worker.ts', import.meta.url), {
118
- type: 'module'
119
- })
120
-
121
- worker.postMessage({
122
- type: 'START',
123
- interval
124
- })
125
-
126
- worker.onmessage = (event: MessageEvent<WorkerResponse>) => {
127
- const data = event.data
128
-
129
- if (data.type === 'CONFIG_VERSION') {
130
- handleVersionChange(data.version)
131
- }
132
-
133
- if (data.type === 'CONFIG_ERROR') {
134
- console.error('配置版本检查失败:', data.message)
135
- }
136
- }
137
-
138
- document.addEventListener('visibilitychange', () => {
139
- if (!document.hidden) {
140
- worker?.postMessage({
141
- type: 'CHECK_NOW'
142
- })
143
- }
144
- })
145
-
146
- window.addEventListener('focus', () => {
147
- worker?.postMessage({
148
- type: 'CHECK_NOW'
149
- })
150
- })
151
- }
152
-
153
- export function stopConfigWatcher(): void {
154
- if (!worker) return
155
-
156
- worker.postMessage({
157
- type: 'STOP'
158
- })
159
-
160
- worker.terminate()
161
- worker = null
162
- }
163
-
164
-
package/test/231231 DELETED
@@ -1,128 +0,0 @@
1
- <template>
2
- <div class="error-page">
3
- <div class="error-content">
4
- <div class="illustration">
5
- <svg viewBox="0 0 420 260" fill="none" xmlns="http://www.w3.org/2000/svg">
6
- <path d="M120 75H310L292 155H95L120 75Z" stroke="#5B83F7" stroke-width="2" />
7
- <path d="M135 90H290" stroke="#5B83F7" stroke-width="14" />
8
- <path d="M104 110H150" stroke="#5B83F7" stroke-width="14" />
9
- <path d="M292 110H345" stroke="#5B83F7" stroke-width="8" />
10
- <path d="M306 135H335" stroke="#5B83F7" stroke-width="5" />
11
- <path d="M260 175H355" stroke="#5B83F7" stroke-width="14" />
12
- <path d="M85 168H250" stroke="#5B83F7" stroke-width="2" />
13
- <circle cx="245" cy="122" r="43" fill="#6B8DFF" />
14
- <path d="M230 107L260 137M260 107L230 137" stroke="white" stroke-width="10" stroke-linecap="round" />
15
- <circle cx="65" cy="155" r="24" stroke="#5B83F7" stroke-width="2" />
16
- <circle cx="95" cy="158" r="34" stroke="#5B83F7" stroke-width="2" />
17
- <circle cx="95" cy="158" r="22" fill="#87A4FF" />
18
- <path d="M48 155C20 150 25 130 50 132C74 134 85 143 92 154" stroke="#5B83F7" stroke-width="2" />
19
- <path d="M30 185H118C124 185 129 190 129 196C129 202 124 207 118 207H82C76 207 71 212 71 218C71 224 76 229 82 229H52" stroke="#5B83F7" stroke-width="2" />
20
- <path d="M40 196H155" stroke="#5B83F7" stroke-width="18" stroke-linecap="round" />
21
- <path d="M92 190V222" stroke="#5B83F7" stroke-width="18" stroke-linecap="round" />
22
- <path d="M58 223H115" stroke="#5B83F7" stroke-width="16" stroke-linecap="round" />
23
- <path d="M270 223H330" stroke="#5B83F7" stroke-width="2" />
24
- <path d="M280 210H310C318 210 325 217 325 225H275C275 217 276 210 280 210Z" fill="#5B83F7" />
25
- <path d="M318 210H333" stroke="#5B83F7" stroke-width="2" />
26
- <path d="M130 62L140 30H315L300 75" stroke="#5B83F7" stroke-width="2" />
27
- <path d="M320 40L305 100" stroke="#5B83F7" stroke-width="2" />
28
- <path d="M115 112L92 175" stroke="#5B83F7" stroke-width="2" />
29
- <path d="M305 78H340" stroke="#476AD7" stroke-width="8" />
30
- <circle cx="148" cy="48" r="3" fill="#5B83F7" />
31
- <circle cx="162" cy="48" r="3" fill="#5B83F7" />
32
- </svg>
33
- </div>
34
-
35
- <div class="text-box">
36
- <h2>抱歉,服务器出错了</h2>
37
- <el-button type="primary" class="back-btn" @click="goHome">
38
- 返回首页
39
- </el-button>
40
- </div>
41
- </div>
42
- </div>
43
- </template>
44
-
45
- <script setup lang="ts">
46
- import { useRouter } from 'vue-router'
47
-
48
- const router = useRouter()
49
-
50
- const goHome = (): void => {
51
- router.push('/')
52
- }
53
- </script>
54
-
55
- <style scoped>
56
- .error-page {
57
- width: 100%;
58
- min-height: 100vh;
59
- background: #f7f8fa;
60
- display: flex;
61
- align-items: center;
62
- justify-content: center;
63
- }
64
-
65
- .error-content {
66
- display: flex;
67
- align-items: center;
68
- gap: 110px;
69
- transform: translateY(-20px);
70
- }
71
-
72
- .illustration {
73
- width: 420px;
74
- height: 260px;
75
- }
76
-
77
- .illustration svg {
78
- width: 100%;
79
- height: 100%;
80
- display: block;
81
- }
82
-
83
- .text-box {
84
- padding-top: 10px;
85
- }
86
-
87
- .text-box h2 {
88
- margin: 0 0 28px;
89
- font-size: 26px;
90
- font-weight: 600;
91
- color: #71809a;
92
- letter-spacing: 1px;
93
- }
94
-
95
- .back-btn {
96
- width: 118px;
97
- height: 48px;
98
- border-radius: 6px;
99
- font-size: 16px;
100
- background: #5b83f7;
101
- border-color: #5b83f7;
102
- }
103
-
104
- .back-btn:hover,
105
- .back-btn:focus {
106
- background: #6b8dff;
107
- border-color: #6b8dff;
108
- }
109
-
110
- @media (max-width: 768px) {
111
- .error-content {
112
- flex-direction: column;
113
- gap: 24px;
114
- }
115
-
116
- .illustration {
117
- width: 320px;
118
- }
119
-
120
- .text-box {
121
- text-align: center;
122
- }
123
-
124
- .text-box h2 {
125
- font-size: 22px;
126
- }
127
- }
128
- </style>
@@ -1,5 +0,0 @@
1
- <svg
2
- viewBox="0 0 400 300"
3
- fill="none"
4
- xmlns="http://www.w3.org/2000/svg"
5
- ><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="47" y="38" width="307" height="224"><path d="M353.3 38H47.5v223.8h305.8V38Z" fill="#fff"/></mask><g mask="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M299.2 200.6H61.6v5.1h240.3l-2.7-5.1Z" fill="#C7DEFF"/><path d="m308.9 185.8-6.5 20H183.7M332.3 127.6h10.6l-5 16.7-14.8-.1-7.2 21.1M328.8 127.4l13.6-39.6M307.6 166 337 84.7H180.6l-9.8 26.9h-10.5M296.6 196l4.3-11.8M157.2 149.2l6.4-17.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-34.8 95.8h136.4l34.7-95.8ZM169.9 166.2l5-13.6-5 13.6Z" fill="#fff"/><path d="m169.9 166.2 5-13.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-4 11.7h135.8l4.5-11.7Z" fill="#006EFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M102.6 159.5h38.3l2.7 36.6h-38.4c-10.1 0-20.9-8.2-20.9-18.3 0-10.1 8.2-18.3 18.3-18.3Z" fill="#DEEBFC"/><path fill-rule="evenodd" clip-rule="evenodd" d="M84.3 174.102c2.5 3.4 10 5 17.9 2.8 16.6-6.5 23.8-3.9 23.8-3.9s.5-3.4 1.3-5c-5.8-3-15.4.3-26.1 3.1-10.7 2.8-15.8-2.5-15.8-2.5-.4 0-1.1 2.8-1.1 5.5Z" fill="#fff"/><path d="M96.5 194.2c-7.2-3.3-12.2-10.5-12.2-19m0 0c0-11.5 9.3-20.8 20.8-20.8h29.4" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8l14.5 19.8Zm-14.5-19.8c0-11.5 9.3-20.8 20.8-20.8l-20.8 20.8Zm20.8-20.8c11.5 0 20.8 9.3 20.8 20.8l-20.8-20.8Zm20.8 20.8c0 8.4-5 15.6-12.1 18.9l12.1-18.9Z" fill="#fff"/><path d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8m0 0c0-11.5 9.3-20.8 20.8-20.8m0 0c11.5 0 20.8 9.3 20.8 20.8m0 0c0 8.4-5 15.6-12.1 18.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M161.5 177.2c0-7.7-6.3-14-14-14s-14 6.3-14 14c0 5.8 3.5 10.8 8.6 12.9.1 0 5.8 1.6 10.7 0 5.3-1.7 8.7-7.1 8.7-12.9Z" fill="#00E4E5"/><path d="M140.5 190.1c-5.8-2.4-9.9-8.2-9.9-14.9 0-8.9 7.2-16.1 16.1-16.1 8.9 0 16.1 7.2 16.1 16.1 0 6.8-4.2 12.5-10.1 14.9M88.4 170.604c2.9 1.3 7.7 2.6 13.6.3 14.7-5.7 22.3-4.3 24.6-3.5M84.5 174.599s5.9 6.5 19 1.7c9.2-3.4 15.3-3.9 18.8-3.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M340.6 112.3h-55.2l-2.7 6.2H338l2.6-6.2Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M236.8 117.9c-16.13 0-29.2 13.07-29.2 29.2s13.07 29.2 29.2 29.2 29.2-13.07 29.2-29.2-13.07-29.2-29.2-29.2Z" fill="#00E4E5"/><path d="M265 123.3c13.1 13.1 13.1 34.4 0 47.6M306 205.9h19.2M61.7 205.9h32.9M181.2 196.2h115.2M47.5 205.9h10v-9.7h73.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M146.7 179.2c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M169.5 196.2c3.9 0 7.1 3.2 7.1 7.1 0 3.9-3.2 7.1-7.1 7.1H144c-2.1 0-3.9 1.7-3.9 3.9v1c0 2.1 1.7 3.9 3.9 3.9h48c5.1 0 9.2 4.1 9.2 9.2s-4.1 9.3-9.2 9.2h-33.8c-2.3 0-4.1 1.8-4.1 4.1s1.8 4.1 4.1 4.1h4.2c4.4 0 8 3.6 8 8s-3.6 8-8 8H111c-3.7 0-6.8-3-6.8-6.8 0-3.7 3-6.8 6.8-6.8h.3c2.3 0 4.1-1.8 4.1-4.1s-1.8-4.1-4.1-4.1H79c-4.5 0-8.1-3.6-8.1-8.1s3.6-8.1 8.1-8.1h37.7c2.1 0 3.9-1.7 3.9-3.9 0-2.1-1.7-3.9-3.9-3.9h-7.9c-4.4 0-7.9-3.5-7.9-7.9s3.5-7.9 7.9-7.9h30.4c2.2 0 3.9-1.8 3.9-3.9V187c0-1.9 1.6-3.5 3.5-3.5s3.5 1.6 3.5 3.5v5.3c0 2.2 1.8 3.9 3.9 3.9h15.5Z" fill="#006EFF"/><path d="m227.8 138.5 18.7 18.7M227.8 157.2l18.7-18.7" stroke="#fff" stroke-width="6"/><path fill-rule="evenodd" clip-rule="evenodd" d="M194.8 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8ZM202.9 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8Z" fill="#fff"/><path d="m291.7 184.3-1.6 4.6h-121M298.1 166.7l22.5-61.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m193 134.1 2.2-5.1h-19.4l-2.3 5.1H193ZM313.2 123.5l2.2-5.1h-24.5l-2.3 5.1h24.6Z" fill="#DEEBFC"/><path d="m164.5 159.2 19.8-54.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M199.6 119.8h-53.2l-4.4 9.3h53.2l4.4-9.3Z" fill="#00E4E5"/><path d="M151.3 129.1H142l4.4-9.3h16.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M353.3 169.4h-67.4l-4.8 12.2h67.3l4.9-12.2Z" fill="#006EFF"/><path d="M332.4 169.4h20.9l-4.9 12.2h-39.7M242.7 235.5v-4.8c0-3.8 3.1-7 7-7h20.2c3.8 0 7 3.1 7 7" stroke="#071F4D"/><path d="M261.1 235.5v-4.8c0-3.8 3.1-7 7-7h13.7c3.8 0 7 3.1 7 7v4.8M242.6 230.7h13.7M235.2 237.7h63.3M224 237.7h6.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.1 141.3H335l3.3-10.7h-10.2l-4 10.7Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M288.3 230.4c0-3.6-2.9-6.5-6.5-6.5h-14.2c-3.6 0-6.5 2.9-6.5 6.5v5.3h27.2v-5.3Z" fill="#071F4D"/><path d="M80.4 228.5H83M87.7 228.5h19.2M146.3 195.8v2c0 3.6-2.9 6.6-6.6 6.6H138M133.4 204.3h1.5M154 249.9h9.4" stroke="#DEEBFC"/><path d="m299.4 141.9 5.1-13.9" stroke="#071F4D"/></g></svg>
@@ -1,16 +0,0 @@
1
- <!-- 500页面 -->
2
- <template>
3
- <ArtException
4
- :data="{
5
- title: '500',
6
- desc: $t('exceptionPage.500'),
7
- btnText: $t('exceptionPage.gohome'),
8
- imgUrl
9
- }"
10
- />
11
- </template>
12
-
13
- <script setup lang="ts">
14
- import imgUrl from '@imgs/svg/500.svg'
15
- defineOptions({ name: 'Exception500' })
16
- </script>
@@ -1,58 +0,0 @@
1
- function formatDate(input, format = 'YYYY-MM-DD HH:mm:ss') {
2
- if (!input) return ''
3
-
4
- let date
5
-
6
- // Date对象
7
- if (input instanceof Date) {
8
- date = input
9
- }
10
- // 时间戳
11
- else if (typeof input === 'number') {
12
- // 秒级时间戳自动转毫秒
13
- date = new Date(
14
- input.toString().length === 10
15
- ? input * 1000
16
- : input
17
- )
18
- }
19
- // 字符串
20
- else if (typeof input === 'string') {
21
- const value = input.trim()
22
-
23
- // 纯数字字符串时间戳
24
- if (/^\d+$/.test(value)) {
25
- date = new Date(
26
- value.length === 10
27
- ? Number(value) * 1000
28
- : Number(value)
29
- )
30
- } else {
31
- // 兼容 Safari
32
- date = new Date(
33
- value.replace(/-/g, '/')
34
- )
35
- }
36
- } else {
37
- return ''
38
- }
39
-
40
- // 无效日期
41
- if (isNaN(date.getTime())) {
42
- return ''
43
- }
44
-
45
- const map = {
46
- YYYY: date.getFullYear(),
47
- MM: String(date.getMonth() + 1).padStart(2, '0'),
48
- DD: String(date.getDate()).padStart(2, '0'),
49
- HH: String(date.getHours()).padStart(2, '0'),
50
- mm: String(date.getMinutes()).padStart(2, '0'),
51
- ss: String(date.getSeconds()).padStart(2, '0')
52
- }
53
-
54
- return format.replace(
55
- /YYYY|MM|DD|HH|mm|ss/g,
56
- key => map[key]
57
- )
58
- }