daikins/.svn/pristine/c3/c3261d94486adb4050e3b95c280...

82 lines
2.2 KiB
Plaintext

import { getArticlePage } from '@/api/daikin/base'
import { pageType } from '@/stores/modules/pages'
const store =pageType()
export const Navs = [
{ key: 'IntelligenceOutside', name: '社外', type: '1' },
{ key: 'IntelligenceWithin', name: '社内', type: '2' },
]
export function useData() {
const route = useRoute()
const { push } = useRouter()
// const type = computed(() => Navs.find((i) => i.key === route.name)?.type)
const state = reactive<any>({
pageNum: 1,
pageSize: 10,
total: 0,
cate: store.page.types,
})
const list = ref<any[]>([])
async function getData() {
const { pageNum, pageSize, cate } = state
if (!cate) return
const _type = ['1', '2', '3'].includes(String(cate)) ? '1' : '2'
list.value = []
state.total = 0
const { rows, total } = await getArticlePage({ type: _type, cate, pageNum, pageSize })
const _rows = rows.map((i: any) => {
i.tagColor = i.tag === '紧急' ? '#e60e0e' : '#2cba06'
return i
})
console.log(rows)
list.value = rows
state.total = total
}
// watch(
// () => route,
// async (r) => {
// await nextTick()
// const { pageNum, pageSize, cate } = r.query
// // state.cate = r.name == 'IntelligenceWithin' ? 4 : 1
// state.cate = Number(cate || 1)
// state.pageNum = Number(pageNum || 1)
// state.pageSize = Number(pageSize || 10)
// // console.log(12, state.cate, cate, pageNum)
// },
// { immediate: true, deep: true },
// )
const lazyState = computed(() => [state.pageNum, state.pageSize, state.cate])
watch(
() => unref(lazyState),
async (v) => {
// await nextTick()
// console.log(123, v)
// const url = location.pathname + '?cate=' + state.cate + '&pageNum=' + state.pageNum + '&pageSize=' + state.pageSize
// history.pushState({ url: url, title: document.title }, document.title, url)
const url = new URL(location as any)
url.searchParams.set('cate', state.cate)
url.searchParams.set('pageNum', state.pageNum)
url.searchParams.set('pageSize', state.pageSize)
history.replaceState({}, '', url)
getData()
},
{ immediate: true, deep: true },
)
return { state, list, getData }
}