forked from opentiny/tiny-vue
168 lines
4.7 KiB
Vue
168 lines
4.7 KiB
Vue
<template>
|
||
<div>
|
||
<tiny-grid ref="tinyGridRef" :fetch-data="fetchData" :pager="pager">
|
||
<template #toolbar>
|
||
<tiny-grid-toolbar
|
||
ref="tinyGridToolbarRef"
|
||
id="custom-remoteservice"
|
||
@remote-setting="handleRemoteSetting"
|
||
:setting="{ remote: true, storage: 'remote', sortable: Sortable }"
|
||
></tiny-grid-toolbar>
|
||
</template>
|
||
<tiny-grid-column type="index" width="60"></tiny-grid-column>
|
||
<tiny-grid-column field="name" title="名称" sortable></tiny-grid-column>
|
||
<tiny-grid-column field="area" title="所属区域" sortable></tiny-grid-column>
|
||
<tiny-grid-column field="address" title="地址"></tiny-grid-column>
|
||
<tiny-grid-column field="introduction" title="公司简介" show-overflow></tiny-grid-column>
|
||
</tiny-grid>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="jsx">
|
||
import { ref } from 'vue'
|
||
import { Grid as TinyGrid, GridColumn as TinyGridColumn, Pager, GridToolbar as TinyGridToolbar } from '@opentiny/vue'
|
||
|
||
import Sortable from 'sortablejs'
|
||
|
||
const pager = ref({
|
||
component: Pager,
|
||
attrs: {
|
||
currentPage: 1,
|
||
pageSize: 3,
|
||
total: 0,
|
||
pageSizes: [3, 5, 10, 20],
|
||
layout: 'total, prev, pager, next, jumper, sizes'
|
||
}
|
||
})
|
||
const fetchData = ref({
|
||
api: getData
|
||
})
|
||
const customConfigs = ref([])
|
||
const tableData = ref([
|
||
{
|
||
id: '1',
|
||
name: 'GFD科技YX公司',
|
||
area: '华东区',
|
||
address: '福州',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '2',
|
||
name: 'WWWW科技YX公司',
|
||
area: '华南区',
|
||
address: '深圳福田区',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '3',
|
||
name: 'RFV有限责任公司',
|
||
area: '华南区',
|
||
address: '中山市',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '4',
|
||
name: 'TGBYX公司',
|
||
area: '华北区',
|
||
address: '梅州',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '5',
|
||
name: 'YHN科技YX公司',
|
||
area: '华南区',
|
||
address: '韶关',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '6',
|
||
name: '康康物业YX公司',
|
||
area: '华北区',
|
||
address: '广州天河区',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '7',
|
||
name: '深圳市福德宝网络技术YX公司',
|
||
area: '华南区',
|
||
address: '清远',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '8',
|
||
name: '西安门福德宝网络技术YX公司',
|
||
area: '华东区',
|
||
address: '厦门',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '9',
|
||
name: 'WWWW科技股份有限子公司',
|
||
area: '华南区',
|
||
address: '韶关',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
},
|
||
{
|
||
id: '10',
|
||
name: 'WSX科技YX公司',
|
||
area: '华南区',
|
||
address: '广州',
|
||
introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。'
|
||
}
|
||
])
|
||
const tinyGridRef = ref()
|
||
let loading
|
||
|
||
getCustomConfigs()
|
||
|
||
function handleRemoteSetting(settings) {
|
||
tinyGridRef.value.reloadCustoms(settings)
|
||
}
|
||
|
||
function getCustomConfigs() {
|
||
setTimeout(() => {
|
||
// 模拟接口请求回来的数据
|
||
loading = false
|
||
|
||
let result = [
|
||
{
|
||
order: null,
|
||
property: 'address',
|
||
visible: true
|
||
},
|
||
{
|
||
order: null,
|
||
property: 'introduction',
|
||
visible: true
|
||
},
|
||
{
|
||
order: null,
|
||
property: 'name',
|
||
visible: true
|
||
},
|
||
{
|
||
order: null,
|
||
property: 'area',
|
||
visible: false
|
||
}
|
||
]
|
||
|
||
// 第二个参数为true时,启用排序功能
|
||
tinyGridRef.value.reloadCustoms(result, true)
|
||
}, 0)
|
||
}
|
||
|
||
function getData({ page }) {
|
||
let curPage = page.currentPage
|
||
let pageSize = page.pageSize
|
||
let offset = (curPage - 1) * pageSize
|
||
|
||
return new Promise((resolve) => {
|
||
resolve({
|
||
result: tableData.value.slice(offset, offset + pageSize),
|
||
page: { total: tableData.value.length }
|
||
})
|
||
})
|
||
}
|
||
</script>
|