refactor: optimize the code

This commit is contained in:
zyronon 2024-04-23 18:30:03 +08:00
parent c64f5fad89
commit 934796b15e
7 changed files with 71 additions and 157 deletions

View File

@ -26,17 +26,12 @@
"axios": "^1.6.8",
"axios-mock-adapter": "^1.22.0",
"core-js": "3.21.1",
"dayjs": "1.11.0",
"gl-matrix": "3.4.3",
"jquery": "^3.7.1",
"libarchive-wasm": "^1.1.0",
"mitt": "3.0.0",
"mobile-select": "1.1.2",
"mockjs": "^1.1.0",
"pinia": "^2.1.7",
"vue": "3.4.21",
"vue-router": "4.3.0",
"vue-switches": "2.0.1",
"libarchive-wasm": "^1.1.0"
"vue-router": "4.3.0"
},
"devDependencies": {
"@commitlint/cli": "^19.2.1",
@ -56,6 +51,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.17.0",
"git-last-commit": "^1.0.1",
"husky": "^9.0.11",
"less": "4.1.3",
"lint-staged": "^15.2.2",
@ -66,8 +62,7 @@
"vite": "^5.1.7",
"vite-plugin-cdn-import": "0.3.5",
"vite-plugin-commonjs": "^0.10.1",
"vue-tsc": "^2.0.6",
"git-last-commit": "^1.0.1"
"vue-tsc": "^2.0.6"
},
"lint-staged": {
"*.{js,ts,vue,jsx,tsx}": [

View File

@ -17,24 +17,12 @@ dependencies:
core-js:
specifier: 3.21.1
version: 3.21.1
dayjs:
specifier: 1.11.0
version: 1.11.0
gl-matrix:
specifier: 3.4.3
version: 3.4.3
jquery:
specifier: ^3.7.1
version: 3.7.1
libarchive-wasm:
specifier: ^1.1.0
version: 1.1.0
mitt:
specifier: 3.0.0
version: 3.0.0
mobile-select:
specifier: 1.1.2
version: 1.1.2
mockjs:
specifier: ^1.1.0
version: 1.1.0
@ -47,9 +35,6 @@ dependencies:
vue-router:
specifier: 4.3.0
version: 4.3.0(vue@3.4.21)
vue-switches:
specifier: 2.0.1
version: 2.0.1
devDependencies:
'@commitlint/cli':
@ -360,6 +345,7 @@ packages:
/@babel/helper-string-parser@7.23.4:
resolution: {integrity: sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==}
engines: {node: '>=6.9.0'}
dev: true
/@babel/helper-validator-identifier@7.22.20:
resolution: {integrity: sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==}
@ -400,14 +386,6 @@ packages:
picocolors: 1.0.0
dev: true
/@babel/parser@7.23.0:
resolution: {integrity: sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==}
engines: {node: '>=6.0.0'}
hasBin: true
dependencies:
'@babel/types': 7.24.0
dev: false
/@babel/parser@7.24.0:
resolution: {integrity: sha512-QuP/FxEAzMSjXygs8v4N9dvdXzEHN4W1oF3PxuWAtPo08UdM17u89RDMgjLn/mlc56iM0HlLmVkO/wgR+rDgHg==}
engines: {node: '>=6.0.0'}
@ -525,6 +503,7 @@ packages:
'@babel/helper-string-parser': 7.23.4
'@babel/helper-validator-identifier': 7.22.20
to-fast-properties: 2.0.0
dev: true
/@commitlint/cli@19.2.1(@types/node@20.12.4)(typescript@5.3.3):
resolution: {integrity: sha512-cbkYUJsLqRomccNxvoJTyv5yn0bSy05BBizVyIcLACkRbVUqYorC351Diw/XFSWC/GtpwiwT2eOvQgFZa374bg==}
@ -1505,14 +1484,6 @@ packages:
'@vue/compiler-core': 3.4.21
'@vue/shared': 3.4.21
/@vue/compiler-sfc@2.7.14:
resolution: {integrity: sha512-aNmNHyLPsw+sVvlQFQ2/8sjNuLtK54TC6cuKnVzAY93ks4ZBrvwQSnkkIh7bsbNhum5hJBS00wSDipQ937f5DA==}
dependencies:
'@babel/parser': 7.23.0
postcss: 8.4.35
source-map: 0.6.1
dev: false
/@vue/compiler-sfc@3.4.21:
resolution: {integrity: sha512-me7epoTxYlY+2CUM7hy9PCDdpMPfIwrOvAXud2Upk10g4YLv9UBW7kL798TvMeDhPthkZ0CONNrK2GoeI1ODiQ==}
dependencies:
@ -2055,17 +2026,9 @@ packages:
hasBin: true
dev: true
/csstype@3.1.2:
resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==}
dev: false
/csstype@3.1.3:
resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==}
/dayjs@1.11.0:
resolution: {integrity: sha512-JLC809s6Y948/FuCZPm5IX8rRhQwOiyMb2TfVVQEixG7P8Lm/gt5S7yoQZmC8x1UehI9Pb7sksEt4xx14m+7Ug==}
dev: false
/debug@4.3.4:
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
engines: {node: '>=6.0'}
@ -2482,10 +2445,6 @@ packages:
split2: 4.2.0
dev: true
/gl-matrix@3.4.3:
resolution: {integrity: sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA==}
dev: false
/glob-parent@5.1.2:
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
engines: {node: '>= 6'}
@ -2747,10 +2706,6 @@ packages:
requiresBuild: true
dev: true
/jquery@3.7.1:
resolution: {integrity: sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==}
dev: false
/js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
dev: true
@ -3038,10 +2993,6 @@ packages:
ufo: 1.4.0
dev: true
/mobile-select@1.1.2:
resolution: {integrity: sha512-FrVAun32DsxLUZziTE1LPlXC72kD13f8N8tqgf7zVWRIOIIJakNxVs8mR2KMzm3QJAYq5+EJ4ji98pHdWJ7ekw==}
dev: false
/mockjs@1.1.0:
resolution: {integrity: sha512-eQsKcWzIaZzEZ07NuEyO4Nw65g0hdWAyurVol1IPl1gahRwY+svqzfgfey8U8dahLwG44d6/RwEzuK52rSa/JQ==}
hasBin: true
@ -3487,6 +3438,8 @@ packages:
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
engines: {node: '>=0.10.0'}
requiresBuild: true
dev: true
optional: true
/source-map@0.7.4:
resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==}
@ -3789,12 +3742,6 @@ packages:
vue: 3.4.21(typescript@5.3.3)
dev: false
/vue-switches@2.0.1:
resolution: {integrity: sha512-rDqBtK3TKy1pEvyZeWmnSHVeXqAcn+ozch7LiNThBzr1QMjg5rhvqBY7uWeli/baDDslf6CXmBJbHPwASJLqoA==}
dependencies:
vue: 2.7.14
dev: false
/vue-template-compiler@2.7.16:
resolution: {integrity: sha512-AYbUWAJHLGGQM7+cNTELw+KsOG9nl2CnSv467WobS5Cv9uk3wFcnr1Etsz2sEIHEZvw1U+o9mRlEO6QbZvUPGQ==}
dependencies:
@ -3814,14 +3761,6 @@ packages:
typescript: 5.3.3
dev: true
/vue@2.7.14:
resolution: {integrity: sha512-b2qkFyOM0kwqWFuQmgd4o+uHGU7T+2z3T+WQp8UBjADfEv2n4FEMffzBmCKNP0IGzOEEfYjvtcC62xaSKeQDrQ==}
deprecated: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details.
dependencies:
'@vue/compiler-sfc': 2.7.14
csstype: 3.1.2
dev: false
/vue@3.4.21(typescript@5.3.3):
resolution: {integrity: sha512-5hjyV/jLEIKD/jYl4cavMcnzKwjMKohureP8ejn3hhEjwhWIhWeuzL2kJAjzl/WyVsgPY56Sy4Z40C3lVshxXA==}
peerDependencies:

View File

@ -30,7 +30,6 @@
<script>
import Dom, { _css } from '../../utils/dom'
import bus, { EVENT_KEY } from '@/utils/bus'
import Utils from '@/utils'
export default {
name: 'FromBottomDialog',

View File

@ -192,7 +192,7 @@ function insertContent(list = props.list) {
bus.emit(EVENT_KEY.CURRENT_ITEM, list[state.localIndex])
}
function dislike(item) {
function dislike() {
// let currentItem = $(wrapperEl.value).find(`.${itemClassName}[data-index=${state.localIndex}]`)
// let replaceItem = getInsEl(item, state.localIndex, true)
// $(replaceItem).css('top', currentItem.css('top'))

View File

@ -1,4 +1,3 @@
import SlideAlbum from '@/components/slide/SlideAlbum.vue'
import SlideUser from '@/components/slide/SlideUser.vue'
import BVideo from '@/components/slide/BVideo.vue'
@ -10,9 +9,9 @@ export function useSlideListItemRender(props) {
case 'img':
node = <img src={item.src} style="height:100%;" alt={''} />
break
case 'imgs':
node = <SlideAlbum isPlay={play} index={index} position={{ uniqueId, index }} {...props} />
break
// case 'imgs':
// node = <SlideAlbum isPlay={play} index={index} position={{ uniqueId, index }} {...props} />
// break
case 'user':
node = <SlideUser {...props} />
break

View File

@ -5,7 +5,6 @@ import ConfirmDialog from '../components/dialog/ConfirmDialog.vue'
import Loading from '../components/Loading.vue'
import Config, { IMG_URL, IS_DEV } from '../config'
import NoticeDialog from '../components/dialog/NoticeDialog.vue'
import dayjs from 'dayjs'
import bus, { EVENT_KEY } from './bus'
import { ArchiveReader, libarchiveWasm } from 'libarchive-wasm'
@ -280,69 +279,6 @@ const Utils = {
}
return defaultValue
},
$storageClear(key, isAll = false) {
if (isAll) {
localStorage.clear()
} else {
localStorage.removeItem(key)
}
},
$dateFormat(val, type) {
if (!val) return
if (typeof val === 'number') {
//
} else {
if (val.length === 10) {
val += '000'
}
if (typeof val === 'string' && (val.length === 10 || val.length === 13)) {
val = Number(val)
}
}
switch (type) {
case 'Y':
return dayjs(val).format('YYYY')
case 'M':
return dayjs(val).format('YYYY-MM')
case 'M_CN':
return dayjs(val).format('YYYY年MM月')
case 'D':
return dayjs(val).format('YYYY-MM-DD')
case 'm':
return dayjs(val).format('YYYY-MM-DD HH:mm')
case 'S':
return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
default:
return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
}
},
$time(time) {
if (String(time).length === 10) {
time = time * 1000
}
const date = new dayjs(time)
const now = new dayjs()
const d = now.valueOf() - date.valueOf()
let str = ''
if (d < 1000 * 60) {
str = '刚刚'
} else if (d < 1000 * 60 * 60) {
str = `${(d / (1000 * 60)).toFixed()}分钟前`
} else if (d < 1000 * 60 * 60 * 24) {
str = `${(d / (1000 * 60 * 60)).toFixed()}小时前`
} else if (d < 1000 * 60 * 60 * 24 * 2) {
str = '1天前'
} else if (d < 1000 * 60 * 60 * 24 * 3) {
str = '2天前'
} else if (d < 1000 * 60 * 60 * 24 * 4) {
str = '3天前'
} else if (date.isSame(now, 'year')) {
str = dayjs(time).format('MM-DD')
} else {
str = dayjs(time).format('YYYY-MM-DD')
}
return str
},
$duration(v) {
if (!v) return '00:00'
const m = Math.floor(v / 60)
@ -376,15 +312,6 @@ const Utils = {
return num
}
},
getCenter(a, b) {
const x = (a.x + b.x) / 2
const y = (a.y + b.y) / 2
return { x, y }
},
// 获取坐标之间的举例
getDistance(start, stop) {
return Math.hypot(stop.x - start.x, stop.y - start.y)
},
updateItem(props, key, val, emit) {
const old = cloneDeep(props.item)
old[key] = val
@ -408,8 +335,39 @@ const Utils = {
export default Utils
export function _dateFormat(val, type) {
return Utils.$dateFormat(val, type)
export function _dateFormat(val, type): string {
if (!val) return
if (String(val).length === 10) {
val = val * 1000
}
const d = new Date(Number(val))
const year = d.getFullYear()
const m = d.getMonth() + 1
const mStr = m < 10 ? '0' + m : m
const day = d.getDate()
const dayStr = day < 10 ? '0' + day : day
const h = d.getHours()
const hStr = h < 10 ? '0' + h : h
const min = d.getMinutes()
const minStr = min < 10 ? '0' + min : min
const sec = d.getSeconds()
const secStr = sec < 10 ? '0' + sec : sec
switch (type) {
case 'Y':
return year + ''
case 'M':
return `${year}-${mStr}`
case 'M_D':
return `${mStr}-${dayStr}`
case 'M_CN':
return `${year}${mStr}`
case 'D':
return `${year}-${mStr}-${dayStr}`
case 'm':
return `${year}-${mStr}-${dayStr} ${hStr}:${minStr}`
default:
return `${year}-${mStr}-${dayStr} ${hStr}:${minStr}:${secStr}`
}
}
export function $no() {
@ -420,8 +378,32 @@ export function $notice(val) {
Utils.$notice(val)
}
export function _time(val) {
return Utils.$time(val)
export function _time(time) {
if (String(time).length === 10) {
time = time * 1000
}
const date = new Date(Number(time))
const now = new Date()
const d = now.valueOf() - date.valueOf()
let str = ''
if (d < 1000 * 60) {
str = '刚刚'
} else if (d < 1000 * 60 * 60) {
str = `${(d / (1000 * 60)).toFixed()}分钟前`
} else if (d < 1000 * 60 * 60 * 24) {
str = `${(d / (1000 * 60 * 60)).toFixed()}小时前`
} else if (d < 1000 * 60 * 60 * 24 * 2) {
str = '1天前'
} else if (d < 1000 * 60 * 60 * 24 * 3) {
str = '2天前'
} else if (d < 1000 * 60 * 60 * 24 * 4) {
str = '3天前'
} else if (date.getFullYear() === now.getFullYear()) {
str = _dateFormat(time, 'M_D')
} else {
str = _dateFormat(time, 'D')
}
return str
}
export function _checkImgUrl(url) {