Files: switch All Files type of List table to Primevue DataTable.

This commit is contained in:
chiayin
2023-04-18 10:46:00 +08:00
parent 5d8fb7aae2
commit ca781f3938

View File

@@ -38,28 +38,14 @@
</ul>
</div>
<!-- All Files type of List -->
<div class="overflow-y-scroll overflow-x-hidden max-h-[calc(100vh_-_480px)] mx-[-8px] scrollbar" v-if="!switchListOrGrid">
<table class="w-full border-separate border-spacing-x-4 text-sm table-fixed">
<thead class="sticky top-0 bg-neutral-10">
<tr>
<th v-for="(item, index) in sortData" :key="index" @click="switchSort(item.sortKey)" class="cursor-pointer">
{{ item.sortName }}
<span class="ml-2">
<IconVector class="inline-block fill-neutral-500"></IconVector>
</span>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(file, index) in allFiles" :key="file.id" @dblclick="enterDiscover(file)">
<td>{{ file.name }}</td>
<td class="text-neutral-500">{{ file.parentLog }}</td>
<td class="text-neutral-500">{{ file.fileType }}</td>
<td class="text-neutral-500">{{ file.owner.name }}</td>
<td class="text-neutral-500">{{ file.updated_at }}</td>
</tr>
</tbody>
</table>
<div class="overflow-y-scroll overflow-x-hidden scrollbar -mx-2 max-h-[calc(100vh_-_480px)]" v-if="!switchListOrGrid">
<DataTable :value="allFiles" dataKey="id" tableClass="w-full !border-separate !border-spacing-x-2 text-sm cursor-pointer" breakpoint="0" @row-dblclick="enterDiscover($event.data)">
<Column field="name" header="Name" bodyClass="font-medium" sortable></Column>
<Column field="parentLog" header="Parent log" bodyClass="text-neutral-500" sortable></Column>
<Column field="fileType" header="File type" bodyClass="text-neutral-500" sortable></Column>
<Column field="owner.name" header="Owner" bodyClass="text-neutral-500" sortable></Column>
<Column field="updated_at" header="Last update" bodyClass="text-neutral-500" sortable></Column>
</DataTable>
</div>
<!-- All Files type of grid -->
<ul class="flex justify-start items-start gap-4 flex-wrap overflow-y-scroll overflow-x-hidden max-h-[calc(100vh_-_480px)] scrollbar" v-else>
@@ -100,30 +86,6 @@
return {
switchListOrGrid: false,
filesTag: 'all',
sortReverseOrder: false,
sortKey: 'name',
sortData: [
{
sortKey: 'name',
sortName: 'Name',
},
{
sortKey: 'parentLog',
sortName: 'Parent log',
},
{
sortKey: 'fileType',
sortName: 'File type',
},
{
sortKey: 'ownerName',
sortName: 'Owner',
},
{
sortKey: 'updated_at',
sortName: 'Last update',
},
],
}
},
setup() {
@@ -149,14 +111,8 @@
allFiles: function() {
if(this.store.allFiles.length !== 0){
let sortFiles = Array.from(this.store.allFiles);
let dataSortOrder = sortFiles.sort((x,y) => x.updated_at - y.updated_at);
let dataSort = this.sortReverseOrder === false? dataSortOrder: dataSortOrder.reverse();
let strSortOrder = sortFiles.sort((x, y)=> x[this.sortKey].localeCompare(y[this.sortKey], 'en'));
let strSort = this.sortReverseOrder === false? strSortOrder: strSortOrder.reverse();
return this.sortKey !== 'updated_at'? strSort: dataSort;
sortFiles.sort((x,y) => new Date(x.updated_at) - new Date(y.updated_at));
return sortFiles;
}
},
/**
@@ -178,14 +134,6 @@
}
},
methods: {
/**
* sort's switch
* @param {string} value
*/
switchSort(value) {
this.sortReverseOrder = (this.sortKey === value)? !this.sortReverseOrder: false;
this.sortKey = value;
},
/**
* 選擇該 files 進入 Discover/Compare/Design 頁面
* @param {object} file
@@ -201,16 +149,23 @@
}
</script>
<style scoped lang="scss">
table {
th {
@apply border-b border-neutral-500 p-3 text-left font-black whitespace-nowrap break-keep overflow-hidden text-ellipsis
<style scoped>
:deep(thead) {
@apply sticky top-0 bg-neutral-10
}
td {
@apply border-b border-neutral-300 p-3 font-medium whitespace-nowrap break-keep overflow-hidden text-ellipsis
:deep(table th) {
@apply border-b !border-neutral-500 p-3 text-left font-black !bg-neutral-10 whitespace-nowrap break-keep overflow-hidden text-ellipsis
}
tbody tr {
@apply hover:bg-primary/50 duration-300 cursor-pointer
:deep(table td) {
@apply border-b border-neutral-300 p-3 whitespace-nowrap break-keep overflow-hidden text-ellipsis
}
:deep(tbody > tr) {
@apply duration-300 cursor-pointer hover:bg-primary/10 focus:!outline-none
}
:deep(.p-sortable-column) {
@apply focus:!shadow-none !text-neutral-900
}
:deep(.p-sortable-column-icon) {
@apply !text-[#6c757d]
}
</style>