feat:重构代码
This commit is contained in:
18
src/utils/article.ts
Normal file
18
src/utils/article.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {Dict, DictResource, getDefaultDict} from "@/types.ts";
|
||||
import {getDictFile} from "@/utils/index.ts";
|
||||
import {cloneDeep} from "lodash-es";
|
||||
import {nanoid} from "nanoid";
|
||||
|
||||
export async function getArticleBookDataByUrl(val: DictResource) {
|
||||
let dictResourceUrl = `./dicts/${val.language}/${val.type}/${val.translateLanguage}/${val.url}`;
|
||||
let s = await getDictFile(dictResourceUrl)
|
||||
let articles = cloneDeep(s.map(v => {
|
||||
v.id = nanoid(6)
|
||||
return v
|
||||
}))
|
||||
return cloneDeep({
|
||||
...getDefaultDict(),
|
||||
...val,
|
||||
articles
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user