refactor: save

This commit is contained in:
zyronon 2024-04-19 19:15:07 +08:00
parent a08a4c85fe
commit adb15c3d92
8 changed files with 191 additions and 147 deletions

View File

@ -33,7 +33,8 @@
"pinia": "^2.1.7",
"vue": "3.4.21",
"vue-router": "4.3.0",
"vue-switches": "2.0.1"
"vue-switches": "2.0.1",
"libarchive-wasm": "^1.1.0"
},
"devDependencies": {
"@commitlint/cli": "^19.2.1",

File diff suppressed because it is too large Load Diff

BIN
public/data/goods.7z Normal file

Binary file not shown.

BIN
public/data/posts.7z Normal file

Binary file not shown.

BIN
public/libarchive.wasm Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
import resource from '../assets/data/resource.js'
import posts6 from '@/assets/data/posts6.json'
import { cloneDeep, random } from '@/utils'
import { _fetch, cloneDeep, random } from '@/utils'
import { BASE_URL, FILE_URL } from '@/config'
import { useBaseStore } from '@/store/pinia'
import axiosInstance from '@/utils/request'
@ -278,7 +278,7 @@ export async function startMock() {
const page = getPage2(config.params)
if (!allRecommendPosts.length) {
const r = await fetch(BASE_URL + '/data/posts.json')
const r = await _fetch(BASE_URL + '/data/posts.7z')
allRecommendPosts = await r.json()
}
return [
@ -298,7 +298,7 @@ export async function startMock() {
mock.onGet(/shop\/recommended/).reply(async (config) => {
const page = getPage2(config.params)
const r2 = await fetch(BASE_URL + '/data/goods.json')
const r2 = await _fetch(BASE_URL + '/data/goods.7z')
const v = await r2.json()
return [
200,

View File

@ -7,6 +7,7 @@ import Config, { IMG_URL } from '../config'
import NoticeDialog from '../components/dialog/NoticeDialog'
import dayjs from 'dayjs'
import bus, { EVENT_KEY } from './bus'
import { ArchiveReader, libarchiveWasm } from 'libarchive-wasm'
const Utils = {
$showLoading() {
@ -679,3 +680,31 @@ export function _notice(val) {
export function _no() {
_notice('未实现')
}
export async function _fetch(url) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
let r = await fetch(url)
if (url.includes('.7z')) {
console.time()
const data = await r.arrayBuffer()
const mod = await libarchiveWasm()
const reader = new ArchiveReader(mod, new Int8Array(data))
for (const entry of reader.entries()) {
if (entry.getPathname().endsWith('.json')) {
let data = new TextDecoder().decode(entry.readData())
resolve({
json() {
return Promise.resolve(JSON.parse(data))
}
})
}
console.timeEnd()
}
reader.free()
} else {
let v = await r.json()
resolve(v)
}
})
}

View File

@ -166,7 +166,7 @@ export default defineConfig({
assetsInlineLimit: 2048
},
esbuild: {
drop: ['console', 'debugger']
// drop: ['console', 'debugger']
},
server: {
port: 3000,