修改响应处理

This commit is contained in:
灌糖包子 2026-03-21 14:20:11 +08:00
parent f9b7f78fe8
commit 26097d5710
Signed by: sookie
GPG Key ID: 0599BECB75C1E68D
4 changed files with 56 additions and 33 deletions

View File

@ -20,23 +20,23 @@ function tabActive() {
})
}
function getElementLeft(element) {    
var actualLeft = element.offsetLeft    
var current = element.offsetParent    
while (current !== null) {      
actualLeft += current.offsetLeft    
current = current.offsetParent  
}  
function getElementLeft(element) {
var actualLeft = element.offsetLeft
var current = element.offsetParent
while (current !== null) {
actualLeft += current.offsetLeft
current = current.offsetParent
}
return actualLeft
}  
function getElementTop(element) {    
var actualTop = element.offsetTop    
var current = element.offsetParent    
while (current !== null) {      
actualTop += current.offsetTop      
current = current.offsetParent    
}    
return actualTop  
}
function getElementTop(element) {
var actualTop = element.offsetTop
var current = element.offsetParent
while (current !== null) {
actualTop += current.offsetTop
current = current.offsetParent
}
return actualTop
}
function scrollStop($dom, top, limit, zIndex, diff) {

View File

@ -1,4 +1,4 @@
import axios from 'axios'
import http from './request'
import PhotoSwipe from 'photoswipe'
import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default'
@ -27,10 +27,10 @@ function loadMoreItems(step) {
scrollLock = true //加载过程中锁定滚动加载
loadTip.style.display = 'block'
// 滚动到底部时调用
axios.get(`${themeConfig.root}api/v2/common/photos`, {params: {start:totalIndex, limit:step}}).then(res => {
http.get('/api/v2/common/photos', {params: {start:totalIndex, limit:step}}).then(res => {
var itemContainer = document.createElement('div')
for(let index = 0 ; index<res.data.data.length && totalIndex<res.data.total ; index++,totalIndex++ ) {
let imgHeight = null, imgFile = res.data.data[index],
for(let index = 0 ; index<res.list.length && totalIndex<res.total ; index++,totalIndex++ ) {
let imgHeight = null, imgFile = res.list[index],
imgSrc = `${themeConfig.pictureCdn}/${imgFile.name}`,
imgThumbnail = imgFile.thumbnail ? `${themeConfig.pictureCdn}/${imgFile.thumbnail}` : imgSrc
let wrapperWidth = photoWallWrapper.getBoundingClientRect().width
@ -69,7 +69,7 @@ function loadMoreItems(step) {
itemContainer.classList.add('item-container')
// itemContainer.insertAdjacentHTML('beforeend', imgItems)
photoWallWrapper.appendChild(itemContainer)
if( totalIndex >= res.data.total ) {
if( totalIndex >= res.total ) {
loadTip.textContent = '没有更多图片啦/(ㄒoㄒ)/~~'
} else {
setTimeout(()=>{

View File

@ -0,0 +1,25 @@
import axios from 'axios'
const http = axios.create({
timeout: 10000,
paramsSerializer: {
indexes: null
}
})
http.interceptors.response.use(res => {
const responseBody = res.data
// 统一响应格式处理
switch (responseBody.code) {
case 0:
// 成功,直接返回数据
return responseBody.data
case -1:
return Promise.reject(new Error(responseBody.message || '请求失败'))
default:
// 其他情况,兼容没有包装格式的响应
return res.data
}
}, err => Promise.reject(err))
export default http

View File

@ -1,4 +1,4 @@
import axios from 'axios'
import http from './request'
import Vue from 'vue/dist/vue.esm'
import waifuTips from '../config/waifu-tip.json'
@ -99,16 +99,15 @@ const vm = new Vue({
limit: this.fullTextSearch.limit,
words: this.fullTextSearchWords
}
axios.get(window.themeConfig.root + 'api/v2/common/search', {params}).then(res => {
http.get('/api/v2/common/search', {params}).then(res => {
this.fullTextSearch.isLoading = false
fullTextSearchTimer = null
let result = res.data
if(!Array.isArray(result.data) || !result.data.length) {
if(!Array.isArray(res.list) || !res.list.length) {
this.fullTextSearch.tip = '未搜索到匹配文章'
} else {
this.fullTextSearchItems.push(...result.data)
this.fullTextSearchItems.push(...res.list)
}
this.fullTextSearch.hasMore = (result.total > this.fullTextSearch.pageNum * this.fullTextSearch.limit)
this.fullTextSearch.hasMore = (res.total > this.fullTextSearch.pageNum * this.fullTextSearch.limit)
}).catch(err => {
this.fullTextSearch.tip = '加载失败, 请刷新重试'
this.fullTextSearch.isLoading = false
@ -169,8 +168,8 @@ const vm = new Vue({
}
},
mounted () {
axios.get(window.themeConfig.root + 'content.json').then((res)=>{
this.items = res.data
fetch(window.themeConfig.root + 'content.json').then(res => res.json()).then(resJson=>{
this.items = resJson
}).catch(err => {
console.warn('加载文章列表失败')
})
@ -225,8 +224,7 @@ function handleSearch(searchItems) {
async function welcomeMessage() {
let now = new Date().getHours()
return axios.get(`${window.themeConfig.root}api/v2/common/config/waifu_tip`).then(res => {
let textTimes = res.data
return http.get('/api/v2/common/config/waifu_tip').then(textTimes => {
let text = null
Array.prototype.sort.call(textTimes, (item1, item2) => {
if(item1.start>item2.start) {
@ -273,8 +271,8 @@ const waifuTools = {
},
'tools.chart'() {
// 一言
axios.get(`${window.themeConfig.root}api/v2/common/hitokoto?length=40&format=json`).then(res => {
this.showMessage(res.data.hitokoto + (res.data.from?`  ——${res.data.from}`:''))
http.get('/api/v2/common/hitokoto?length=40&format=json').then(res => {
this.showMessage(res.hitokoto + (res.from?`  ——${res.from}`:''))
})
},
'tools.search'() {