Skip to content

Commit

Permalink
chore: 减小包体大小
Browse files Browse the repository at this point in the history
  • Loading branch information
journey-ad committed Dec 21, 2023
1 parent 6b2607d commit ff6f4c3
Show file tree
Hide file tree
Showing 16 changed files with 9,708 additions and 9,929 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build": "vue-cli-service build --modern",
"analyze": "vue-cli-service build --modern --report",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@vant/touch-emulator": "^1.2.0",
"@vue/cli-plugin-pwa": "^4.5.19",
"axios": "^0.19.2",
"core-js": "^3.34.0",
"dayjs": "^1.11.10",
"file-saver": "^2.0.2",
"gif.js": "^0.2.0",
"gifshot": "^0.4.5",
"gsap": "^3.12.4",
"js-base64": "^2.5.2",
"jszip": "^3.4.0",
"localforage": "^1.10.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.21",
"mobile-device-detect": "^0.4.3",
"moment": "^2.24.0",
"opencc-js": "^1.0.5",
"register-service-worker": "^1.7.2",
"swiper": "^5.3.6",
Expand All @@ -30,7 +31,6 @@
"vue": "^2.7.15",
"vue-awesome-swiper": "^4.1.0",
"vue-concise-slider": "^3.4.4",
"vue-moment": "^4.1.0",
"vue-router": "^3.6.5",
"vue-waterfall2": "1.10.6",
"vuex": "^3.6.2",
Expand Down
6 changes: 3 additions & 3 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from './http'
import { DBStorage, Expires } from '@/utils/storage'
import moment from 'moment'
import dayjs from 'dayjs'
import { Base64 } from 'js-base64';

const isSupportWebP = (() => {
Expand Down Expand Up @@ -241,8 +241,8 @@ const api = {
* @param {Number} page 页数
* @param {String} date YYYY-MM-DD 默认为「前天」
*/
async getRankList(mode = 'weekly', page = 1, date = moment().subtract(2, 'days').format('YYYY-MM-DD')) {
date = moment(date).format('YYYY-MM-DD')
async getRankList(mode = 'weekly', page = 1, date = dayjs().subtract(2, 'days').format('YYYY-MM-DD')) {
date = dayjs(date).format('YYYY-MM-DD')

const cache_key = `rankList_${mode}_${date}_${page}`
let rankList = await DBStorage.get(cache_key)
Expand Down
14 changes: 14 additions & 0 deletions src/components/dayjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dayjs from 'dayjs'
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)

export default {
install(Vue) {
Vue.dayjs = dayjs
Vue.prototype.$dayjs = dayjs

Vue.filter('dayjs', function (value, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(value).format(format)
})
}
}
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Moment from 'vue-moment'
import Dayjs from '@/components/dayjs'
import Icon from 'vue-svg-icon/Icon.vue'
import { Toast, Lazyload, ImagePreview } from 'vant';
import '@vant/touch-emulator';
Expand All @@ -20,7 +20,7 @@ import './polyfill'

import './registerServiceWorker'

Vue.use(Moment);
Vue.use(Dayjs);
Vue.use(Toast);
Vue.use(Lazyload, {
lazyComponent: true,
Expand Down
2 changes: 1 addition & 1 deletion src/views/Artwork/components/Meta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
<div class="date">
<span class="created">{{
artwork.created | moment("YYYY-MM-DD hh:mm")
artwork.created | dayjs("YYYY-MM-DD hh:mm")
}}</span>
<span class="view">
<Icon name="view" class="icon"></Icon>
Expand Down
13 changes: 4 additions & 9 deletions src/views/Artwork/components/Related.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
@load="getRelated()"
>
<div class="card-box__wrapper" ref="cardBox">
<waterfall
:col="col"
:width="itemWidth"
:gutterWidth="0"
:data="artList"
>
<waterfall :col="col" :width="itemWidth" :gutterWidth="0" :data="artList">
<router-link
:to="{
name: 'Artwork',
Expand All @@ -41,7 +36,7 @@
import { Cell, Swipe, SwipeItem, Icon, List, PullRefresh } from "vant";
import ImageCard from "@/components/ImageCard";
import api from "@/api";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
export default {
name: "Related",
props: {
Expand Down Expand Up @@ -69,7 +64,7 @@ export default {
this.curPage = 1;
this.artList = [];
},
getRelated: _.throttle(async function () {
getRelated: throttle(async function () {
if (!this.artwork.id) return;
let newList;
let res = await api.getRelated(this.artwork.id, this.curPage);
Expand All @@ -78,7 +73,7 @@ export default {
let artList = JSON.parse(JSON.stringify(this.artList));
artList = artList.concat(newList);
artList = _.uniqBy(artList, "id");
artList = uniqBy(artList, "id");
this.artList = artList;
this.loading = false;
Expand Down
6 changes: 3 additions & 3 deletions src/views/Home/components/Daily.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import { Cell, Swipe, SwipeItem, Icon, List, PullRefresh } from "vant";
import ImageCard from "@/components/ImageCard";
import api from "@/api";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
export default {
name: "Daily",
data() {
Expand All @@ -60,14 +60,14 @@ export default {
url(id, index) {
return api.url(id, index);
},
getRankList: _.throttle(async function () {
getRankList: throttle(async function () {
let res = await api.getRankList("day", this.curPage);
if (res.status === 0) {
let newList = res.data;
let artList = JSON.parse(JSON.stringify(this.artList));
artList.push(...newList);
artList = _.uniqBy(artList, "id");
artList = uniqBy(artList, "id");
this.artList = artList;
this.loading = false;
Expand Down
20 changes: 5 additions & 15 deletions src/views/Home/components/Moments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@
</template>
</van-cell>
<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="getLatest"
>
<van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getLatest">
<div class="card-box__wrapper" ref="cardBox">
<waterfall
:col="col"
:width="itemWidth"
:gutterWidth="0"
:data="artList"
>
<waterfall :col="col" :width="itemWidth" :gutterWidth="0" :data="artList">
<router-link
:to="{
name: 'Artwork',
Expand All @@ -41,7 +31,7 @@
import { Cell, Swipe, SwipeItem, Icon, List, PullRefresh } from "vant";
import ImageCard from "@/components/ImageCard";
import api from "@/api";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
export default {
name: "Moments",
data() {
Expand Down Expand Up @@ -70,15 +60,15 @@ export default {
}
this.isLoading = false;
},
getLatest: _.throttle(async function () {
getLatest: throttle(async function () {
let newList;
let res = await api.getLatest();
if (res.status === 0) {
newList = res.data;
let artList = JSON.parse(JSON.stringify(this.artList));
artList.push(...newList);
artList = _.uniqBy(artList, "id");
artList = uniqBy(artList, "id");
this.artList = artList;
this.loading = false;
Expand Down
42 changes: 29 additions & 13 deletions src/views/Novel/components/novel-reader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@

<script>
import { Slider } from "vant";
import { debounce } from "lodash";
import { debounce } from "lodash-es";
import gsap from "gsap";
import * as OpenCC from "opencc-js";
import { LocalStorage } from "@/utils/storage";
import { setThemeColor } from "@/utils";
const loadOpenCC = () => import("opencc-js");
const _READER_SETTING_KEY = "__PIXIV_readerSetting";
Expand All @@ -148,16 +148,29 @@ let readerSetting = LocalStorage.get(_READER_SETTING_KEY, {
zhTrans: 0,
});
const converter = {
s2t: new OpenCC.Converter({
from: "cn",
to: "tw",
}),
t2s: new OpenCC.Converter({
from: "tw",
to: "cn",
}),
};
class Converter {
constructor() {
this.inited = false;
}
async init() {
const OpenCC = await loadOpenCC();
this.s2t = new OpenCC.Converter({
from: "cn",
to: "tw",
});
this.t2s = new OpenCC.Converter({
from: "tw",
to: "cn",
});
this.inited = true;
}
}
const converter = new Converter();
export default {
name: "novel-reader",
Expand Down Expand Up @@ -309,13 +322,16 @@ export default {
}
setThemeColor(this.viewerStyle.backgroundColor);
},
parseNovel() {
async parseNovel() {
if (!this.content) return;
let content = this.content;
// content = "载".repeat(10000);
const _now = Date.now();
if (!converter.inited && this.readerConfig.zhTrans.value > 0) {
await converter.init();
}
switch (this.readerConfig.zhTrans.value) {
case 1: {
content = converter.t2s(content);
Expand Down
16 changes: 8 additions & 8 deletions src/views/Rank/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
</template>

<script>
import moment from "moment";
import dayjs from "dayjs";
import { List, Loading, Empty } from "vant";
import ImageCard from "@/components/ImageCard";
import Nav from "./components/Nav";
import Top3 from "./components/Top3";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
import api from "@/api";
export default {
name: "Rank",
Expand All @@ -89,9 +89,9 @@ export default {
col: 2,
itemWidth: 0,
scrollTop: 0,
minDate: moment("2007-09-13").toDate(),
maxDate: moment().subtract(2, "days").toDate(),
date: moment().subtract(2, "days").toDate(),
minDate: dayjs("2007-09-13").toDate(),
maxDate: dayjs().subtract(2, "days").toDate(),
date: dayjs().subtract(2, "days").toDate(),
isDatePickerShow: false,
curType: "daily",
curPage: 1,
Expand All @@ -116,7 +116,7 @@ export default {
},
computed: {
dateNum() {
return moment(this.date).date();
return dayjs(this.date).date();
},
},
watch: {
Expand Down Expand Up @@ -149,15 +149,15 @@ export default {
getIOType(type) {
return this.menu[type] ? this.menu[type].io : null;
},
getRankList: _.throttle(async function () {
getRankList: throttle(async function () {
let type = this.getIOType(this.curType);
let res = await api.getRankList(type, this.curPage, this.date);
if (res.status === 0) {
let newList = res.data;
let artList = JSON.parse(JSON.stringify(this.artList));
artList.push(...newList);
artList = _.uniqBy(artList, "id");
artList = uniqBy(artList, "id");
this.artList = artList;
this.loading = false;
Expand Down
6 changes: 3 additions & 3 deletions src/views/Search/components/ImageSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<script>
import { Uploader } from "vant";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
export default {
computed: {
resultList() {
Expand All @@ -56,8 +56,8 @@ export default {
};
});
list = _.uniqBy(list, "id");
list = _.orderBy(list, "similarity", "desc");
list = uniqBy(list, "id");
list = orderBy(list, "similarity", "desc");
return list;
}
Expand Down
6 changes: 3 additions & 3 deletions src/views/Search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import NovelCard from "@/components/NovelCard";
import Tags from "./components/Tags";
import ImageSearch from "./components/ImageSearch";
import { mapState, mapActions } from "vuex";
import _ from "lodash";
import { throttle, uniqBy } from "lodash-es";
import api from "@/api";
export default {
beforeRouteEnter(to, from, next) {
Expand Down Expand Up @@ -236,7 +236,7 @@ export default {
this.resize();
this.search(this.keywords);
},
search: _.throttle(async function (val) {
search: throttle(async function (val) {
val = val || this.keywords;
this.keywords__ = val;
val = val.trim();
Expand All @@ -255,7 +255,7 @@ export default {
let artList = JSON.parse(JSON.stringify(this.artList));
artList.push(...newList);
artList = _.uniqBy(artList, "id");
artList = uniqBy(artList, "id");
this.artList = artList;
this.loading = false;
Expand Down
Loading

0 comments on commit ff6f4c3

Please sign in to comment.