useBookList.js
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { ref } from 'vue'
import axios from '@/utils/axios';
import { Toast } from 'vant';
import { useRoute } from 'vue-router';
export const useBookList = () => {
const $route = useRoute();
const emptyStatus = ref(false);
// tslint:disable-next-line: variable-name
const kg_id = $route.query.kg_id ? $route.query.kg_id : '';
const kgInfo = ref({
id: '',
logo: '',
name: '',
book_list: []
});
if (kg_id) { // 从学校列表进入
axios.get('/srv/?a=kg_book_list', {
params: {
kg_id
}
})
.then(res => {
if (res.data.code === 1) {
kgInfo.value = res.data.data;
if (!kgInfo.value.book_list.length) {
emptyStatus.value = true;
}
} else {
// tslint:disable-next-line: no-console
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
// tslint:disable-next-line: no-console
console.error(err);
})
} else { // 从访客进入
axios.get('/srv/?a=book_list')
.then(res => {
if (res.data.code === 1) {
kgInfo.value = {
book_list: res.data.data
}
if (!kgInfo.value.book_list.length) {
emptyStatus.value = true;
}
} else {
// tslint:disable-next-line: no-console
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
// tslint:disable-next-line: no-console
console.error(err);
})
}
return {
kg_id,
kgInfo,
emptyStatus
}
}