修改响应处理
This commit is contained in:
parent
f9b7f78fe8
commit
26097d5710
@ -20,23 +20,23 @@ function tabActive() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getElementLeft(element) {
|
function getElementLeft(element) {
|
||||||
var actualLeft = element.offsetLeft
|
var actualLeft = element.offsetLeft
|
||||||
var current = element.offsetParent
|
var current = element.offsetParent
|
||||||
while (current !== null) {
|
while (current !== null) {
|
||||||
actualLeft += current.offsetLeft
|
actualLeft += current.offsetLeft
|
||||||
current = current.offsetParent
|
current = current.offsetParent
|
||||||
}
|
}
|
||||||
return actualLeft
|
return actualLeft
|
||||||
}
|
}
|
||||||
function getElementTop(element) {
|
function getElementTop(element) {
|
||||||
var actualTop = element.offsetTop
|
var actualTop = element.offsetTop
|
||||||
var current = element.offsetParent
|
var current = element.offsetParent
|
||||||
while (current !== null) {
|
while (current !== null) {
|
||||||
actualTop += current.offsetTop
|
actualTop += current.offsetTop
|
||||||
current = current.offsetParent
|
current = current.offsetParent
|
||||||
}
|
}
|
||||||
return actualTop
|
return actualTop
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollStop($dom, top, limit, zIndex, diff) {
|
function scrollStop($dom, top, limit, zIndex, diff) {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import axios from 'axios'
|
import http from './request'
|
||||||
import PhotoSwipe from 'photoswipe'
|
import PhotoSwipe from 'photoswipe'
|
||||||
import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default'
|
import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default'
|
||||||
|
|
||||||
@ -27,10 +27,10 @@ function loadMoreItems(step) {
|
|||||||
scrollLock = true //加载过程中锁定滚动加载
|
scrollLock = true //加载过程中锁定滚动加载
|
||||||
loadTip.style.display = 'block'
|
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')
|
var itemContainer = document.createElement('div')
|
||||||
for(let index = 0 ; index<res.data.data.length && totalIndex<res.data.total ; index++,totalIndex++ ) {
|
for(let index = 0 ; index<res.list.length && totalIndex<res.total ; index++,totalIndex++ ) {
|
||||||
let imgHeight = null, imgFile = res.data.data[index],
|
let imgHeight = null, imgFile = res.list[index],
|
||||||
imgSrc = `${themeConfig.pictureCdn}/${imgFile.name}`,
|
imgSrc = `${themeConfig.pictureCdn}/${imgFile.name}`,
|
||||||
imgThumbnail = imgFile.thumbnail ? `${themeConfig.pictureCdn}/${imgFile.thumbnail}` : imgSrc
|
imgThumbnail = imgFile.thumbnail ? `${themeConfig.pictureCdn}/${imgFile.thumbnail}` : imgSrc
|
||||||
let wrapperWidth = photoWallWrapper.getBoundingClientRect().width
|
let wrapperWidth = photoWallWrapper.getBoundingClientRect().width
|
||||||
@ -69,7 +69,7 @@ function loadMoreItems(step) {
|
|||||||
itemContainer.classList.add('item-container')
|
itemContainer.classList.add('item-container')
|
||||||
// itemContainer.insertAdjacentHTML('beforeend', imgItems)
|
// itemContainer.insertAdjacentHTML('beforeend', imgItems)
|
||||||
photoWallWrapper.appendChild(itemContainer)
|
photoWallWrapper.appendChild(itemContainer)
|
||||||
if( totalIndex >= res.data.total ) {
|
if( totalIndex >= res.total ) {
|
||||||
loadTip.textContent = '没有更多图片啦/(ㄒoㄒ)/~~'
|
loadTip.textContent = '没有更多图片啦/(ㄒoㄒ)/~~'
|
||||||
} else {
|
} else {
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
|
|||||||
25
themes/yilia/source-src/js/request.js
Normal file
25
themes/yilia/source-src/js/request.js
Normal 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
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import axios from 'axios'
|
import http from './request'
|
||||||
import Vue from 'vue/dist/vue.esm'
|
import Vue from 'vue/dist/vue.esm'
|
||||||
import waifuTips from '../config/waifu-tip.json'
|
import waifuTips from '../config/waifu-tip.json'
|
||||||
|
|
||||||
@ -99,16 +99,15 @@ const vm = new Vue({
|
|||||||
limit: this.fullTextSearch.limit,
|
limit: this.fullTextSearch.limit,
|
||||||
words: this.fullTextSearchWords
|
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
|
this.fullTextSearch.isLoading = false
|
||||||
fullTextSearchTimer = null
|
fullTextSearchTimer = null
|
||||||
let result = res.data
|
if(!Array.isArray(res.list) || !res.list.length) {
|
||||||
if(!Array.isArray(result.data) || !result.data.length) {
|
|
||||||
this.fullTextSearch.tip = '未搜索到匹配文章'
|
this.fullTextSearch.tip = '未搜索到匹配文章'
|
||||||
} else {
|
} 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 => {
|
}).catch(err => {
|
||||||
this.fullTextSearch.tip = '加载失败, 请刷新重试'
|
this.fullTextSearch.tip = '加载失败, 请刷新重试'
|
||||||
this.fullTextSearch.isLoading = false
|
this.fullTextSearch.isLoading = false
|
||||||
@ -169,8 +168,8 @@ const vm = new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
axios.get(window.themeConfig.root + 'content.json').then((res)=>{
|
fetch(window.themeConfig.root + 'content.json').then(res => res.json()).then(resJson=>{
|
||||||
this.items = res.data
|
this.items = resJson
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.warn('加载文章列表失败')
|
console.warn('加载文章列表失败')
|
||||||
})
|
})
|
||||||
@ -225,8 +224,7 @@ function handleSearch(searchItems) {
|
|||||||
|
|
||||||
async function welcomeMessage() {
|
async function welcomeMessage() {
|
||||||
let now = new Date().getHours()
|
let now = new Date().getHours()
|
||||||
return axios.get(`${window.themeConfig.root}api/v2/common/config/waifu_tip`).then(res => {
|
return http.get('/api/v2/common/config/waifu_tip').then(textTimes => {
|
||||||
let textTimes = res.data
|
|
||||||
let text = null
|
let text = null
|
||||||
Array.prototype.sort.call(textTimes, (item1, item2) => {
|
Array.prototype.sort.call(textTimes, (item1, item2) => {
|
||||||
if(item1.start>item2.start) {
|
if(item1.start>item2.start) {
|
||||||
@ -273,8 +271,8 @@ const waifuTools = {
|
|||||||
},
|
},
|
||||||
'tools.chart'() {
|
'tools.chart'() {
|
||||||
// 一言
|
// 一言
|
||||||
axios.get(`${window.themeConfig.root}api/v2/common/hitokoto?length=40&format=json`).then(res => {
|
http.get('/api/v2/common/hitokoto?length=40&format=json').then(res => {
|
||||||
this.showMessage(res.data.hitokoto + (res.data.from?` ——${res.data.from}`:''))
|
this.showMessage(res.hitokoto + (res.from?` ——${res.from}`:''))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
'tools.search'() {
|
'tools.search'() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user