useVideoList.js
4 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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: '普通话' }); // 默认选中普通话
/**
* 切换视频语言回调
* @param {*} type
*/
const toggleLanguage = (type) => {
if (type === 'mandarin') {
checkMandarin.value = true;
checkLocalism.value = false;
} else {
checkMandarin.value = false;
checkLocalism.value = true;
}
// 修改默认语言绑定数据
if (checkLocalism.value) {
// tslint:disable-next-line:no-string-literal
chooseLanguage.value = { text: columns.value[0]['text'], val: columns.value[0]['val'] }
} else {
chooseLanguage.value = { text: '普通话', val: '普通话' };
}
// 切换语言需要更新列表数据
onReload()
}
// 方言选择项
let columns = ref([
{ text: '所有方言', val: '所有方言' },
])
//
axios.get('/srv/?a=localism_list')
.then(res => {
if (res.data.code === 1) {
let arr = [];
_.each(res.data.data, item => {
arr.push({
text: item,
val: item
})
});
columns.value = _.concat(columns.value, arr);
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
const showPicker = ref(false);
/**
* 选择方言确认后回调
* @param {*} param
*/
const onConfirm = ({ selectedOptions }) => {
showPicker.value = false;
chooseLanguage.value = {
text: selectedOptions[0].text,
val: selectedOptions[0].val
}
onReload()
};
// 绑定页面数据
const bookInfo = ref('');
// tslint:disable-next-line: variable-name
const prod_list = ref([]);
const limit = ref(10)
const offset = ref(0)
// 处理书籍下作品列表
const loading = ref(false);
const finished = ref(false);
// 因为不能让空图标提前出来的写法
const finishedTextStatus = ref(false);
const emptyStatus = 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);
prod_list.value = _.uniqBy(prod_list.value, 'id');
offset.value = prod_list.value.length;
loading.value = false;
// 数据全部加载完成
if (!res.data.data.prod_list.length) {
// 加载状态结束
finished.value = true;
}
// 空数据提示
if (!prod_list.value.length) {
finishedTextStatus.value = false;
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);
})
};
/**
* 重载刷新程序
*/
const onReload = () => {
offset.value = 0
prod_list.value = []
loading.value = true;
finished.value = false;
onLoad()
}
return {
toggleLanguage,
onLoad,
columns,
prod_list,
finished,
loading,
bookInfo,
showPicker,
checkLocalism,
checkMandarin,
onConfirm,
chooseLanguage,
finishedTextStatus,
emptyStatus,
}
}