Compare commits

..

3 Commits

Author SHA1 Message Date
fb1cbbada4
升级 Vue 2 到 Vue 3
- 升级 vue 2.7.16 → 3.5.14
- 重构 slider.js:new Vue() 迁移到 createApp()
- data 改为函数形式,移除 filters 改用 methods
- 更新模板 tools.ejs:过滤器语法改为方法调用
- 代码风格优化:箭头函数、const/let、简化数组操作

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 22:46:48 +08:00
6f6fcebd18
移除 axios,改用原生 fetch 实现 HTTP 请求
- 从 package.json 移除 axios 依赖
- 重构 request.js:用原生 fetch API 替代 axios
- 实现参数序列化、超时控制(AbortController)、统一响应处理
- 保持 http.get/http.post API 兼容,减少 bundle 体积

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 22:18:57 +08:00
7d827d5db8
升级 yilia 主题构建工具链
- 升级 babel 相关依赖至 ^7.26.0,配置按需引入 core-js polyfill
- 升级 webpack 5.70.0 → 5.97.1,webpack-cli 4.9.2 → 5.1.4
- 升级 css-loader、postcss-loader、less-loader 等至最新版本
- 移除废弃的 file-loader/url-loader,改用 webpack5 内置 asset modules
- 移除 babel-polyfill 和 leancloud-storage,添加 @babel/runtime 和 core-js
- 升级 vue 2.6.14 → 2.7.16,axios 1.13.6 → 1.8.4
- 添加 browserslist 配置

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 22:12:52 +08:00
8 changed files with 2541 additions and 8055 deletions

View File

@ -1,6 +1,9 @@
{ {
"presets": [ "presets": [
"@babel/preset-env" ["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": 3
}]
], ],
"plugins": [ "plugins": [
"@babel/transform-runtime" "@babel/transform-runtime"

View File

@ -60,7 +60,7 @@
</div> </div>
<ul class="search-ul"> <ul class="search-ul">
<li class="search-li" v-for="(item,index) in items" :key="index" v-show="!item.isHide"> <li class="search-li" v-for="(item,index) in items" :key="index" v-show="!item.isHide">
<a :href="item.path|urlformat" class="search-title"><i class="icon icon-quote-left"></i> <a :href="urlformat(item.path)" class="search-title"><i class="icon icon-quote-left"></i>
<span v-text="item.title"></span> <span v-text="item.title"></span>
</a> </a>
<p class="search-time" v-if="item.date"> <p class="search-time" v-if="item.date">

File diff suppressed because it is too large Load Diff

View File

@ -18,39 +18,36 @@
"author": "litten", "author": "litten",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"babel-polyfill": "^6.23.0", "@babel/runtime": "^7.26.0",
"leancloud-storage": "^3.7.3", "core-js": "^3.40.0",
"photoswipe": "^4.1.3", "photoswipe": "^4.1.3",
"qrious": "^4.0.2", "qrious": "^4.0.2",
"scrollreveal": "^4.0.5", "scrollreveal": "^4.0.9",
"vue": "^2.6.14" "vue": "^3.5.14"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.17.5", "@babel/core": "^7.26.0",
"@babel/plugin-transform-runtime": "^7.17.0", "@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.26.0",
"autoprefixer": "^10.4.2", "autoprefixer": "^10.4.20",
"axios": "^1.13.6", "babel-loader": "^9.2.1",
"babel-loader": "8.3.0",
"clean-webpack-plugin": "^4.0.0", "clean-webpack-plugin": "^4.0.0",
"css-loader": "^5.2.7", "css-loader": "^7.1.2",
"file-loader": "^6.2.0", "html-webpack-plugin": "^5.6.3",
"html-webpack-plugin": "^5.5.0", "less": "^4.2.2",
"less": "^4.1.3", "less-loader": "^12.2.0",
"less-loader": "^11.1.0", "mini-css-extract-plugin": "^2.9.2",
"mini-css-extract-plugin": "^2.6.0", "postcss": "^8.5.3",
"postcss-loader": "^6.2.1", "postcss-loader": "^8.1.1",
"terser-webpack-plugin": "^5.3.1", "terser-webpack-plugin": "^5.3.11",
"url-loader": "^4.1.1", "webpack": "^5.97.1",
"webpack": "^5.70.0", "webpack-cli": "^5.1.4"
"webpack-cli": "^4.9.2"
}, },
"browserslist": [ "browserslist": [
"> 1%", "> 1%",
"last 2 versions", "last 2 versions",
"not dead", "not dead",
"iOS >= 7", "iOS >= 10",
"Android >= 4", "Android >= 5"
"not ie <= 8"
] ]
} }

View File

@ -1,6 +1,5 @@
module.exports = { module.exports = {
plugins: [ plugins: [
"autoprefixer", "autoprefixer"
"postcss-preset-env"
] ]
} }

View File

@ -1,14 +1,19 @@
import axios from 'axios' const DEFAULT_TIMEOUT = 10000
const http = axios.create({ function serializeParams(params) {
timeout: 10000, if (!params) return ''
paramsSerializer: { const query = Object.entries(params)
indexes: null .filter(([, v]) => v !== undefined && v !== null)
.flatMap(([k, v]) => Array.isArray(v) ? v.map(item => `${encodeURIComponent(k)}=${encodeURIComponent(item)}`) : [`${encodeURIComponent(k)}=${encodeURIComponent(v)}`])
.join('&')
return query ? '?' + query : ''
}
function handleResponse(res) {
if (!res.ok) {
return Promise.reject(new Error(`HTTP ${res.status}`))
} }
}) return res.json().then(responseBody => {
http.interceptors.response.use(res => {
const responseBody = res.data
// 统一响应格式处理 // 统一响应格式处理
switch (responseBody.code) { switch (responseBody.code) {
case 0: case 0:
@ -18,8 +23,30 @@ http.interceptors.response.use(res => {
return Promise.reject(new Error(responseBody.message || '请求失败')) return Promise.reject(new Error(responseBody.message || '请求失败'))
default: default:
// 其他情况,兼容没有包装格式的响应 // 其他情况,兼容没有包装格式的响应
return res.data return responseBody
} }
}, err => Promise.reject(err)) })
}
async function request(url, options = {}) {
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT)
return fetch(url, { ...options, signal: controller.signal })
.then(res => { clearTimeout(timer); return handleResponse(res) })
.catch(err => { clearTimeout(timer); return Promise.reject(err) })
}
const http = {
get(url, { params } = {}) {
return request(url + serializeParams(params))
},
post(url, data) {
return request(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
}
}
export default http export default http

View File

@ -1,17 +1,22 @@
import http from './request' import http from './request'
import Vue from 'vue/dist/vue.esm' import { createApp } from 'vue'
import waifuTips from '../config/waifu-tip.json' import waifuTips from '../config/waifu-tip.json'
function setScrollZero() { function setScrollZero() {
let $sct = document.querySelectorAll('.tools-section') document.querySelectorAll('.tools-section').forEach(em => {
Array.prototype.forEach.call($sct, (em) => {
em.scrollTop = 0 em.scrollTop = 0
}) })
} }
function urlformat(str) {
return (window.themeConfig && window.themeConfig.root) ? window.themeConfig.root + str : '/' + str
}
var waifuTipTimer = null, fullTextSearchTimer = null var waifuTipTimer = null, fullTextSearchTimer = null
const vm = new Vue({
el: '#container', const vm = createApp({
data: { data() {
return {
isCtnShow: false, isCtnShow: false,
isShow: undefined, isShow: undefined,
items: [], items: [],
@ -37,13 +42,15 @@ const vm = new Vue({
showTools: false // 显示工具栏 showTools: false // 显示工具栏
}, },
themeConfig: window.themeConfig themeConfig: window.themeConfig
}
}, },
methods: { methods: {
stop (event) { urlformat,
stop(event) {
event.stopPropagation() event.stopPropagation()
}, },
openSlider (event, type, isMobile) { openSlider(event, type, isMobile) {
if(isMobile && this.isShow) { if (isMobile && this.isShow) {
this.hideSlider() this.hideSlider()
return return
} }
@ -56,32 +63,32 @@ const vm = new Vue({
this.isCtnShow = true this.isCtnShow = true
setScrollZero() setScrollZero()
}, },
hideSlider () { hideSlider() {
if (this.isShow) { if (this.isShow) {
this.isShow = false this.isShow = false
setTimeout(() => {this.isCtnShow = false}, 300) setTimeout(() => { this.isCtnShow = false }, 300)
} }
}, },
linkMouseover(name) { linkMouseover(name) {
if(name === 'waifu' && waifuTipTimer) return if (name === 'waifu' && waifuTipTimer) return
this.showMessage(waifuTips.mouseover[name], 3000) this.showMessage(waifuTips.mouseover[name], 3000)
}, },
toolsClick(name) { toolsClick(name) {
this.showMessage(waifuTips.click[name]) this.showMessage(waifuTips.click[name])
if(name in waifuTools) { if (name in waifuTools) {
waifuTools[name].call(this) waifuTools[name].call(this)
} }
}, },
addSearchItem(query, type='title') { addSearchItem(query, type = 'title') {
if(query) { if (query) {
query = query.trim() query = query.trim()
} }
// 如果已存在相同的查询条件, 则不加入 // 如果已存在相同的查询条件, 则不加入
var isExist = Array.prototype.some.call(this.searchItems, searchItem => { const isExist = this.searchItems.some(searchItem => {
return searchItem.query === query && searchItem.type === type return searchItem.query === query && searchItem.type === type
}) })
if(!isExist && query) { if (!isExist && query) {
this.searchItems.push({query, type}) this.searchItems.push({ query, type })
} }
this.search = null this.search = null
}, },
@ -91,18 +98,18 @@ const vm = new Vue({
this.$refs.mask.classList.add('in') this.$refs.mask.classList.add('in')
}, },
loadSearchResult() { loadSearchResult() {
this.fullTextSearch.pageNum ++ this.fullTextSearch.pageNum++
this.fullTextSearch.isLoading = true this.fullTextSearch.isLoading = true
this.fullTextSearch.tip = undefined this.fullTextSearch.tip = undefined
let params = { const params = {
pageNum: this.fullTextSearch.pageNum, pageNum: this.fullTextSearch.pageNum,
limit: this.fullTextSearch.limit, limit: this.fullTextSearch.limit,
words: this.fullTextSearchWords words: this.fullTextSearchWords
} }
http.get('/api/v2/common/search', {params}).then(res => { http.get('/api/v2/common/search', { params }).then(res => {
this.fullTextSearch.isLoading = false this.fullTextSearch.isLoading = false
fullTextSearchTimer = null fullTextSearchTimer = null
if(!Array.isArray(res.list) || !res.list.length) { if (!Array.isArray(res.list) || !res.list.length) {
this.fullTextSearch.tip = '未搜索到匹配文章' this.fullTextSearch.tip = '未搜索到匹配文章'
} else { } else {
this.fullTextSearchItems.push(...res.list) this.fullTextSearchItems.push(...res.list)
@ -115,62 +122,53 @@ const vm = new Vue({
}) })
}, },
searchKeydown(event) { searchKeydown(event) {
if(event.keyCode == 13){ // 回车键 if (event.keyCode == 13) { // 回车键
this.addSearchItem(this.search) this.addSearchItem(this.search)
} else if(event.keyCode == 8 && !this.search) { // 退格键 } else if (event.keyCode == 8 && !this.search) { // 退格键
this.searchItems.pop() this.searchItems.pop()
} }
}, },
showMessage (text, time) { showMessage(text, time) {
if(!text) return if (!text) return
if(Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1)-1] if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1) - 1]
this.waifu.tip = text this.waifu.tip = text
this.waifu.tipOpacity = 1 this.waifu.tipOpacity = 1
if(waifuTipTimer) { if (waifuTipTimer) {
clearTimeout(waifuTipTimer) clearTimeout(waifuTipTimer)
waifuTipTimer = null waifuTipTimer = null
} }
waifuTipTimer = setTimeout(()=>{ waifuTipTimer = setTimeout(() => {
this.waifu.tipOpacity = 0 this.waifu.tipOpacity = 0
waifuTipTimer = null waifuTipTimer = null
}, time || 5000) }, time || 5000)
} }
}, },
filters: {
urlformat (str) {
return (window.themeConfig && window.themeConfig.root) ? window.themeConfig.root + str : '/' + str
}
},
watch: { watch: {
searchItems (newVal, oldVal) { searchItems(newVal) {
if(newVal && newVal.length) { if (newVal && newVal.length) {
handleSearch.call(this, newVal) handleSearch.call(this, newVal)
} else { } else {
this.items.forEach(function(item){ this.items.forEach(item => { item.isHide = false })
item.isHide = false
})
} }
}, },
fullTextSearchWords (newVal, oldVal) { fullTextSearchWords(newVal) {
this.fullTextSearch.hasMore = false this.fullTextSearch.hasMore = false
this.fullTextSearchItems.isLoading = false this.fullTextSearchItems.isLoading = false
this.fullTextSearch.tip = undefined this.fullTextSearch.tip = undefined
this.fullTextSearchItems.splice(0, this.fullTextSearchItems.length) this.fullTextSearchItems.splice(0, this.fullTextSearchItems.length)
if(fullTextSearchTimer) { if (fullTextSearchTimer) {
clearTimeout(fullTextSearchTimer) clearTimeout(fullTextSearchTimer)
fullTextSearchTimer = null fullTextSearchTimer = null
} }
if(!newVal) { if (!newVal) return
return
}
this.fullTextSearch.pageNum = 0 this.fullTextSearch.pageNum = 0
fullTextSearchTimer = setTimeout(this.loadSearchResult.bind(this), 500) fullTextSearchTimer = setTimeout(this.loadSearchResult.bind(this), 500)
} }
}, },
mounted () { mounted() {
fetch(window.themeConfig.root + 'content.json').then(res => res.json()).then(resJson=>{ fetch(window.themeConfig.root + 'content.json').then(res => res.json()).then(resJson => {
this.items = resJson this.items = resJson
}).catch(err => { }).catch(() => {
console.warn('加载文章列表失败') console.warn('加载文章列表失败')
}) })
welcomeMessage().then(msg => { welcomeMessage().then(msg => {
@ -179,44 +177,39 @@ const vm = new Vue({
document.addEventListener('copy', () => { document.addEventListener('copy', () => {
this.showMessage('你都复制了些什么呀,转载要记得加上出处哦') this.showMessage('你都复制了些什么呀,转载要记得加上出处哦')
}) })
// 隐藏模态框 const hideModal = () => {
let hideModal = (function() { document.querySelectorAll('.page-modal').forEach(modal => {
let modals = document.querySelectorAll('.page-modal')
Array.prototype.forEach.call(modals, modal => {
modal.classList.remove('in') modal.classList.remove('in')
}) })
this.$refs.mask.classList.remove('in') this.$refs.mask.classList.remove('in')
}).bind(this) }
// 隐藏模态框
this.$refs.mask.addEventListener('click', hideModal) this.$refs.mask.addEventListener('click', hideModal)
Array.prototype.forEach.call(document.querySelectorAll('.js-modal-close'), modalClose => { document.querySelectorAll('.js-modal-close').forEach(modalClose => {
modalClose.addEventListener('click', hideModal) modalClose.addEventListener('click', hideModal)
}) })
}, },
created() { created() {
// 夜间模式 // 夜间模式
let night = localStorage.getItem('night') const night = localStorage.getItem('night')
try { if (night === 'true') {
if(night && eval(night)) document.querySelector('body').classList.add('night') document.querySelector('body').classList.add('night')
} catch (e){}
} }
}) }
}).mount('#container')
function handleSearch(searchItems) { function handleSearch(searchItems) {
this.items.forEach(articleItem => { this.items.forEach(articleItem => {
articleItem.isHide = !Array.prototype.every.call(searchItems, searchItem => { articleItem.isHide = !searchItems.every(searchItem => {
switch(searchItem.type) { switch (searchItem.type) {
case 'title': case 'title':
return articleItem.title.toLowerCase().indexOf(searchItem.query.toLowerCase()) !== -1 return articleItem.title.toLowerCase().indexOf(searchItem.query.toLowerCase()) !== -1
case 'tag' : case 'tag':
return Array.prototype.some.call(articleItem.tags, tag => { return articleItem.tags.some(tag => tag.name === searchItem.query)
return tag.name === searchItem.query case 'category':
}) return articleItem.categories.some(category => category.name === searchItem.query)
case 'category' : case 'date':
return Array.prototype.some.call(articleItem.categories, category => { return articleItem.date && (articleItem.date.substr(0, 7) === searchItem.query)
return category.name === searchItem.query
})
case 'date' :
return articleItem.date && ( articleItem.date.substr(0,7) === searchItem.query )
} }
}) })
}) })
@ -226,22 +219,14 @@ async function welcomeMessage() {
let now = new Date().getHours() let now = new Date().getHours()
return http.get('/api/v2/common/config/waifu_tip').then(textTimes => { return http.get('/api/v2/common/config/waifu_tip').then(textTimes => {
let text = null let text = null
Array.prototype.sort.call(textTimes, (item1, item2) => { textTimes.sort((a, b) => a.start - b.start)
if(item1.start>item2.start) { textTimes.forEach(textTime => {
return 1 if (now > textTime.start && now <= textTime.end) {
} else if(item1.start<item2.start) {
return -1
} else {
return 0
}
})
Array.prototype.forEach.call(textTimes, textTime => {
if(now > textTime.start && now <= textTime.end) {
text = textTime.text text = textTime.text
} }
}) })
if(!text) { if (!text) {
text = textTimes[textTimes.length-1].text text = textTimes[textTimes.length - 1].text
} }
return text return text
}) })
@ -271,8 +256,8 @@ const waifuTools = {
}, },
'tools.chart'() { 'tools.chart'() {
// 一言 // 一言
http.get('/api/v2/common/hitokoto', { params: {format: 'json'} }).then(res => { http.get('/api/v2/common/hitokoto', { params: { format: 'json' } }).then(res => {
this.showMessage(res.hitokoto + (res.from?`  ——${res.from}`:'')) this.showMessage(res.hitokoto + (res.from ? `  ——${res.from}` : ''))
}) })
}, },
'tools.search'() { 'tools.search'() {

View File

@ -24,7 +24,7 @@ module.exports = function(env, argv) {
})] })]
}, },
entry: { entry: {
main: ['babel-polyfill', './source-src/js/main.js'], main: './source-src/js/main.js',
slider: './source-src/js/slider.js', slider: './source-src/js/slider.js',
mobile: './source-src/js/mobile.js', mobile: './source-src/js/mobile.js',
viewer: './source-src/js/viewer.js' viewer: './source-src/js/viewer.js'
@ -37,39 +37,25 @@ module.exports = function(env, argv) {
module: { module: {
rules: [{ rules: [{
test: /\.js$/, test: /\.js$/,
use: { use: 'babel-loader',
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-proposal-class-properties'],
},
},
exclude: /node_modules/ exclude: /node_modules/
},{ },{
test: /\.less$/, test: /\.less$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'] use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'less-loader']
},{ },{
test: /\.css$/, test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'] use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
},{ },{
test: /\.(png|jpe?g|gif|ico)$/, test: /\.(png|jpe?g|gif|ico)$/,
use: { type: 'asset/resource',
loader: 'file-loader', generator: {
options: { filename: 'images/[name].[contenthash:6][ext]'
name: '[name].[contenthash:6].[ext]',
outputPath: 'images',
esModule: false // 不使用es6的模块语法
}
} }
},{ },{
test: /\.(svg|eot|ttf|woff2?|otf)$/, test: /\.(svg|eot|ttf|woff2?|otf)$/,
use: { type: 'asset/resource',
loader: 'file-loader', generator: {
options: { filename: 'fonts/[name].[contenthash:6][ext]'
name: '[name].[contenthash:6].[ext]',
outputPath: 'fonts',
esModule: false // 不使用es6的模块语法
}
} }
} }
] ]