mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 07:28:37 +08:00
feat(subscribe): update display list based on user role and improve sorting logic
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "moviepilot",
|
"name": "moviepilot",
|
||||||
"version": "2.1.4",
|
"version": "2.1.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"bin": "dist/service.js",
|
"bin": "dist/service.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -35,6 +35,18 @@ const historyDialog = ref(false)
|
|||||||
// 订阅顺序配置
|
// 订阅顺序配置
|
||||||
const orderConfig = ref<{ id: number }[]>([])
|
const orderConfig = ref<{ id: number }[]>([])
|
||||||
|
|
||||||
|
// 显示的订阅列表
|
||||||
|
const displayList = ref<Subscribe[]>([])
|
||||||
|
|
||||||
|
// 监听dataList变化,同步更新displayList
|
||||||
|
watch(dataList, () => {
|
||||||
|
// 从Vuex Store中获取用户信息
|
||||||
|
const superUser = store.state.auth.superUser
|
||||||
|
const userName = store.state.auth.userName
|
||||||
|
if (superUser) displayList.value = dataList.value.filter(data => data.type === props.type)
|
||||||
|
else displayList.value = dataList.value.filter(data => data.type === props.type && data.username === userName)
|
||||||
|
})
|
||||||
|
|
||||||
// 加载顺序
|
// 加载顺序
|
||||||
async function loadSubscribeOrderConfig() {
|
async function loadSubscribeOrderConfig() {
|
||||||
// 顺序配置
|
// 顺序配置
|
||||||
@@ -48,15 +60,17 @@ async function loadSubscribeOrderConfig() {
|
|||||||
localStorage.setItem('MP_SUBSCRIBE_ORDER', JSON.stringify(orderConfig.value))
|
localStorage.setItem('MP_SUBSCRIBE_ORDER', JSON.stringify(orderConfig.value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 排序
|
|
||||||
if (orderConfig.value) {
|
|
||||||
sortSubscribeOrder()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按order的顺序排序
|
// 按order的顺序排序
|
||||||
function sortSubscribeOrder() {
|
function sortSubscribeOrder() {
|
||||||
displayList.value.sort((a, b) => {
|
if (!orderConfig.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (dataList.value.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataList.value.sort((a, b) => {
|
||||||
const aIndex = orderConfig.value.findIndex((item: { id: number }) => item.id === a.id)
|
const aIndex = orderConfig.value.findIndex((item: { id: number }) => item.id === a.id)
|
||||||
const bIndex = orderConfig.value.findIndex((item: { id: number }) => item.id === b.id)
|
const bIndex = orderConfig.value.findIndex((item: { id: number }) => item.id === b.id)
|
||||||
return (aIndex === -1 ? 999 : aIndex) - (bIndex === -1 ? 999 : bIndex)
|
return (aIndex === -1 ? 999 : aIndex) - (bIndex === -1 ? 999 : bIndex)
|
||||||
@@ -67,6 +81,7 @@ function sortSubscribeOrder() {
|
|||||||
async function saveSubscribeOrder() {
|
async function saveSubscribeOrder() {
|
||||||
// 顺序配置
|
// 顺序配置
|
||||||
const orderObj = displayList.value.map(item => ({ id: item.id }))
|
const orderObj = displayList.value.map(item => ({ id: item.id }))
|
||||||
|
orderConfig.value = orderObj
|
||||||
const orderString = JSON.stringify(orderObj)
|
const orderString = JSON.stringify(orderObj)
|
||||||
localStorage.setItem('MP_SUBSCRIBE_ORDER', orderString)
|
localStorage.setItem('MP_SUBSCRIBE_ORDER', orderString)
|
||||||
|
|
||||||
@@ -83,6 +98,8 @@ async function fetchData() {
|
|||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
dataList.value = await api.get('subscribe/')
|
dataList.value = await api.get('subscribe/')
|
||||||
|
// 排序
|
||||||
|
sortSubscribeOrder()
|
||||||
loading.value = false
|
loading.value = false
|
||||||
isRefreshed.value = true
|
isRefreshed.value = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -96,28 +113,12 @@ const loading = ref(false)
|
|||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
async function onRefresh({ done }: { done: any }) {
|
async function onRefresh({ done }: { done: any }) {
|
||||||
await fetchData()
|
await fetchData()
|
||||||
await loadSubscribeOrderConfig()
|
|
||||||
done('ok')
|
done('ok')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示的订阅列表
|
|
||||||
const displayList = ref<Subscribe[]>([])
|
|
||||||
|
|
||||||
// 监听dataList变化,同步更新displayList
|
|
||||||
watch(dataList, () => {
|
|
||||||
// 从Vuex Store中获取用户信息
|
|
||||||
const superUser = store.state.auth.superUser
|
|
||||||
const userName = store.state.auth.userName
|
|
||||||
if (superUser) displayList.value = dataList.value.filter(data => data.type === props.type)
|
|
||||||
else displayList.value = dataList.value.filter(data => data.type === props.type && data.username === userName)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 过滤数据,管理员用户显示全部,非管理员只显示自己的订阅
|
|
||||||
const filteredDataList = computed(() => {})
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchData()
|
|
||||||
await loadSubscribeOrderConfig()
|
await loadSubscribeOrderConfig()
|
||||||
|
await fetchData()
|
||||||
if (props.subid) {
|
if (props.subid) {
|
||||||
// 找到这个订阅
|
// 找到这个订阅
|
||||||
const sub = dataList.value.find(sub => sub.id.toString() == props.subid?.toString())
|
const sub = dataList.value.find(sub => sub.id.toString() == props.subid?.toString())
|
||||||
@@ -131,7 +132,6 @@ onMounted(async () => {
|
|||||||
onActivated(async () => {
|
onActivated(async () => {
|
||||||
if (!loading.value) {
|
if (!loading.value) {
|
||||||
await fetchData()
|
await fetchData()
|
||||||
await loadSubscribeOrderConfig()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user