import { keys } from 'idb-keyval' import '../css/list.css' import { createSignal } from 'solid-js' import { fetchData } from '../../../http/api' type dataList = { id: string } interface Props { instanceData: Omit & { title?:string, istop?:number }, key: any, setList: Function, infoList: any, popShow: Function, setErrorFun:Function } export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: Props) => { //设置数据 const instanceItem = instanceData let instance = instanceItem || { id: '', name: '' } const isTouchDevice = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0 //置顶数据排序 const getToppingItem = (arr: any) => { let toppingArr: { id: string, istop: boolean }[] = [] let copyArr: any[]=[] arr.map((res: { istop: boolean; id: string }, i: number) => { if (res.istop) { copyArr.push(arr[i]) }else{ toppingArr.push(arr[i]) } }) // console.log([...copyArr,...toppingArr]) return [...copyArr,...toppingArr] } //设置数据置顶 const setItemTop = (uniqid: string, item: any) => { return new Promise((res, rej) => { fetchData({ uniqid }, function (data) { if (data.code === 200) { item.istop = item.istop ? 0 : 1 } else { setErrorFun(data.message) } res(null) }, !item.istop?'/chat/top':'/chat/cancelTop', 'POST'); }) } //置顶排序 const setDataTop = (e: MouseEvent, key: string) => { let arr = JSON.parse(JSON.stringify(infoList)) let item = arr[key] setItemTop(item.uniqid, item).then(res=>{ let toppindItem = getToppingItem(arr) setList('data', (list: null[]) => [...toppindItem]) }) e.stopPropagation() } return (
{instance.title as any}
popShow('open', null, null, instance.title)} >
setDataTop(e, key())} >
popShow('delete', e, key())} >
) }