useVideoList.js
2.97 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { ref } from 'vue'
import axios from '@/utils/axios';
import _ from 'lodash'
import { Toast } from 'vant';
export const useVideoList = ($route) => {
// 切换视频语言
const checkMandarin = ref(true); // 普通话选项卡
const checkLocalism = ref(false); // 方言选项卡
const chooseLanguage = ref({ text: '普通话', val: '普通话' }); // 默认选中普通话
const toggleLanguage = () => {
checkMandarin.value = !checkMandarin.value;
checkLocalism.value = !checkLocalism.value;
// 修改默认语言绑定数据
if (checkLocalism.value) {
// tslint:disable-next-line:no-string-literal
chooseLanguage.value = { text: columns[0]['text'], val: columns[0]['val'] }
} else {
chooseLanguage.value = { text: '普通话', val: '普通话' };
}
// 切换语言需要更新列表数据
offset.value = 0
prod_list.value = []
loading.value = true;
finished.value = false;
onLoad()
}
// 方言选择项
const columns = [
{ text: '所有方言', val: '所有方言' },
{ text: '沪语', val: '沪语' },
{ text: '粤语', val: '粤语' },
];
const showPicker = ref(false);
const onConfirm = ({ selectedOptions }) => {
showPicker.value = false;
chooseLanguage.value = {
text: selectedOptions[0].text,
val: selectedOptions[0].val
}
};
// 绑定页面数据
const bookInfo = ref('');
// tslint:disable-next-line: variable-name
const prod_list = ref([]);
const limit = ref(1)
const offset = ref(0)
// 处理书籍下作品列表
const loading = ref(false);
const finished = ref(false);
const onLoad = () => {
// 异步更新数据
axios.get('/srv/?a=book_info', {
params: {
book_id: $route.query.id,
localism_type: chooseLanguage.value.text,
limit: limit.value,
offset: offset.value
}
})
.then(res => {
if (res.data.code === 1) {
bookInfo.value = res.data.data;
prod_list.value = _.concat(prod_list.value, res.data.data.prod_list);
offset.value = prod_list.value.length;
loading.value = false;
// 数据全部加载完成
if (!res.data.data.prod_list.length) {
// 加载状态结束
finished.value = true;
}
} else {
// tslint:disable-next-line: no-console
console.warn(res);
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
// tslint:disable-next-line: no-console
console.error(err);
})
};
return {
toggleLanguage,
onLoad,
columns,
prod_list,
finished,
loading,
bookInfo,
showPicker,
checkLocalism,
checkMandarin,
onConfirm,
chooseLanguage
}
}