提交 5498f4b6 authored 作者: 王鹏飞's avatar 王鹏飞

bug fixes

上级 f8994073
import axios from 'axios'
import _ from 'lodash'
import store from '../store'
import router from '../router'
export default class API {
constructor (config) {
constructor(config) {
/* 创建一个 自定义配置axios实例 */
// 让ajax携带cookie
axios.defaults.withCredentials = true
......@@ -23,14 +24,16 @@ export default class API {
}
/* 获取当前Vue创建实例 */
getVueInstance () {
getVueInstance() {
return window.G.$instance_vue
}
/* 重新封装 请求时的执行函数 */
_request (_config = {}) {
_request(_config = {}) {
/* 具体执行请求成功后业务逻辑前,先执行该方法 */
const beforeSuccess = _config.beforeSuccess ? _config.beforeSuccess : this._reqSuccess
const beforeSuccess = _config.beforeSuccess
? _config.beforeSuccess
: this._reqSuccess
/* 具体执行请求失败后业务逻辑前,先执行该方法 */
const beforeFail = _config.beforeFail ? _config.beforeFail : this._reqFail
const headers = {
......@@ -38,7 +41,9 @@ export default class API {
}
_config.headers = _.assignIn(_config.headers, headers)
/* 判别 传输方式 */
if (_config.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
if (
_config.headers['Content-Type'] === 'application/x-www-form-urlencoded'
) {
let str = ''
const _obj = _config.data || _config.params
for (const key in _obj) {
......@@ -60,8 +65,10 @@ export default class API {
_config.data = fr
}
/* 创建并根据参数发起请求 */
return this._axios(_config)
.then(beforeSuccess.bind(this), beforeFail.bind(this))
return this._axios(_config).then(
beforeSuccess.bind(this),
beforeFail.bind(this)
)
}
/**
......@@ -69,7 +76,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 返回数据
*/
_reqSuccess (res) {
_reqSuccess(res) {
const { status, data } = res
let err = null
if (status === 200) {
......@@ -85,7 +92,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 如果未到达 response 阶段,则无res.response
*/
_reqFail (res) {
_reqFail(res) {
// console.log(res.response, '========')
let err = null
if (res.code === 'ECONNABORTED') {
......@@ -93,17 +100,21 @@ export default class API {
} else if (res.response) {
const { status, data } = res.response
if (data) {
if (status === 402) {
if (window.G.$instance_vue.$store.state.isWeapp) {
wx.miniProgram.navigateTo({ url: `/pages/web/index?src=${window.location.origin}/pay` })
if (status === 403) {
if (store.state.isWeapp) {
wx.miniProgram.navigateTo({ url: '/pages/login/index' })
} else {
window.G.$instance_vue.$router.replace({
path: '/pay'
router.push('/login')
}
}
if (status === 402) {
if (store.state.isWeapp) {
wx.miniProgram.navigateTo({
url: `/pages/web/index?src=${window.location.origin}/pay`
})
} else {
router.replace({ path: '/pay' })
}
// window.G.$instance_vue.$router.replace({
// path: '/pay'
// })
}
}
err = new Error(JSON.stringify(res.response))
......@@ -116,22 +127,28 @@ export default class API {
}
/* 重新实现 get请求 */
get (url, data, config) {
return this._request(_.assignIn({ url, method: 'GET', params: data }, config))
get(url, data, config) {
return this._request(
_.assignIn({ url, method: 'GET', params: data }, config)
)
}
/* 重新实现 post请求 */
post (url, data, config) {
return this._request(_.assignIn({ url, method: 'POST', data: data }, config))
post(url, data, config) {
return this._request(
_.assignIn({ url, method: 'POST', data: data }, config)
)
}
/* 重新实现 put请求 */
put (url, data, config) {
put(url, data, config) {
return this._request(_.assignIn({ url, method: 'PUT', data: data }, config))
}
/* 重新实现 delete请求 */
delete (url, data, config) {
return this._request(_.assignIn({ url, method: 'DELETE', params: data }, config))
delete(url, data, config) {
return this._request(
_.assignIn({ url, method: 'DELETE', params: data }, config)
)
}
}
<template>
<div class="search-bar">
<form action @submit.prevent="onSearch">
<input
type="search"
class="search-input"
:placeholder="placeholder"
v-model="currentValue"
v-bind="$attrs"
@input="onChange"
ref="formInput"
/>
<div class="inner">
<input
type="search"
class="search-input"
:placeholder="placeholder"
v-model="currentValue"
v-bind="$attrs"
@input="onChange"
ref="formInput"
/>
<input type="button" value="搜索" class="search-button" @click="onSearch" />
</div>
</form>
</div>
</template>
......@@ -73,4 +76,14 @@ export default {
border-radius: 0.1rem;
outline: none;
}
.search-button {
margin-left: 0.2rem;
color: #222;
font-size: 0.3rem;
appearance: none;
background-color: transparent;
}
.inner {
display: flex;
}
</style>
import Vue from 'vue' // 引入vue框架
import VueRouter from 'vue-router' // 使用 vue-router
import createRouter from './router' // router定义
import router from './router' // router定义
import store from '@/store'
import VueI18n from 'vue-i18n' // 使用 国际化
import createI18n from './assets/languages' // 国际化定义
......@@ -24,7 +24,6 @@ require('promise.prototype.finally').shim()
/* 兼容处理 end */
Vue.use(VueRouter)
const router = createRouter()
Vue.use(VueI18n)
const i18n = createI18n()
......
......@@ -26,10 +26,14 @@ export default {
message: '加载中...',
forbidClick: true
})
api.getCourseList().then(response => {
this.courseList = response
this.$toast.clear()
})
api
.getCourseList()
.then(response => {
this.courseList = response
})
.finally(() => {
this.$toast.clear()
})
}
},
beforeMount() {
......
......@@ -62,15 +62,19 @@ export default {
forbidClick: true
})
this.loaded = false
api.getCourse(this.courseId).then(response => {
this.loaded = true
response.chapters = response.chapters.filter(item => {
item.children = item.children.filter(child => child.type === 2)
return item.children.length
api
.getCourse(this.courseId)
.then(response => {
this.loaded = true
response.chapters = response.chapters.filter(item => {
item.children = item.children.filter(child => child.type === 2)
return item.children.length
})
this.detail = response
})
.finally(() => {
this.$toast.clear()
})
this.detail = response
this.$toast.clear()
})
}
},
beforeMount() {
......
......@@ -65,19 +65,23 @@ export default {
message: '加载中...',
forbidClick: true
})
api.getCourseTagList(this.courseId).then(response => {
this.$emit('ready', response)
this.detail = response
this.messageList = response.chapters.map((item, index) => {
return {
id: this.genId(index),
type: 1,
from: 'system',
payload: item
}
api
.getCourseTagList(this.courseId)
.then(response => {
this.$emit('ready', response)
this.detail = response
this.messageList = response.chapters.map((item, index) => {
return {
id: this.genId(index),
type: 1,
from: 'system',
payload: item
}
})
})
.finally(() => {
this.$toast.clear()
})
this.$toast.clear()
})
},
// 输入搜索
onSearch() {
......
......@@ -50,11 +50,15 @@ export default {
forbidClick: true
})
this.loaded = false
api.getCourseTag(this.tagId).then(response => {
this.loaded = true
this.detail = response
this.$toast.clear()
})
api
.getCourseTag(this.tagId)
.then(response => {
this.loaded = true
this.detail = response
})
.finally(() => {
this.$toast.clear()
})
},
// 去知识点考试页面
toExamPage() {
......
......@@ -60,11 +60,15 @@ export default {
forbidClick: true
})
this.loaded = false
api.getCourseTagList(this.courseId).then(response => {
this.loaded = true
this.detail = response
this.$toast.clear()
})
api
.getCourseTagList(this.courseId)
.then(response => {
this.loaded = true
this.detail = response
})
.finally(() => {
this.$toast.clear()
})
},
onClick({ id }) {
if (this.isTest) {
......
......@@ -56,10 +56,14 @@ export default {
message: '加载中...',
forbidClick: true
})
api.getFreeCourseList().then(response => {
this.courseList = response
this.$toast.clear()
})
api
.getFreeCourseList()
.then(response => {
this.courseList = response
})
.finally(() => {
this.$toast.clear()
})
},
// 搜索
toSearch() {
......
import Router from 'vue-router'
import routes from './routes'
export default () => {
return new Router({
routes,
mode: 'history', // 还有一个 hash 默认
fallback: true, // 浏览器不支持 history时,自动改成 hash方式
scrollBehavior (to, from, savedPosition) { // 每次打开,滚动到 最顶端
return { x: 0, y: 0 }
}
})
}
export default new Router({
routes,
mode: 'history', // 还有一个 hash 默认
fallback: true, // 浏览器不支持 history时,自动改成 hash方式
scrollBehavior(to, from, savedPosition) {
// 每次打开,滚动到 最顶端
return { x: 0, y: 0 }
}
})
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论