| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <script setup lang="ts">
- import { computed, ref } from "vue";
- import {
- type PlusColumn,
- useTable,
- PlusSearch,
- PlusTable,
- PageInfo,
- ButtonsCallBackParams
- } from "plus-pro-components";
- import { number } from "echarts";
- defineOptions({
- name: "SplitTable"
- });
- interface TableRow {
- id: number;
- name: string;
- status: string;
- tag: string;
- time: Date;
- }
- const state = ref({});
- const { tableData, buttons, pageInfo } = useTable<TableRow[]>();
- const columns: PlusColumn[] = [
- {
- label: "名称",
- prop: "name",
- valueType: "copy",
- tooltip: "名称最多显示6个字符"
- },
- {
- label: "状态",
- prop: "status",
- valueType: "select",
- options: [
- {
- label: "未解决",
- value: "0",
- color: "red"
- },
- {
- label: "已解决",
- value: "1",
- color: "blue"
- },
- {
- label: "解决中",
- value: "2",
- color: "yellow"
- },
- {
- label: "失败",
- value: "3",
- color: "red"
- }
- ]
- },
- {
- label: "时间",
- prop: "time",
- valueType: "date-picker"
- },
- {
- label: "数量",
- prop: "number",
- valueType: "input-number",
- fieldProps: { precision: 2, step: 2 }
- },
- {
- label: "城市",
- prop: "city",
- valueType: "cascader",
- options: [
- {
- value: "zhejiang",
- label: "浙江",
- children: [
- {
- value: "hangzhou",
- label: "杭州",
- children: [
- {
- value: "xihu",
- label: "西湖"
- }
- ]
- },
- {
- value: "ningbo",
- label: "宁波",
- children: [
- {
- value: "dongqianlake",
- label: "东钱湖"
- }
- ]
- }
- ]
- },
- {
- value: "jiangsu",
- label: "江苏",
- children: [
- {
- value: "nanjing",
- label: "南京",
- children: [
- {
- value: "zhonghuamen",
- label: "中华门"
- }
- ]
- }
- ]
- }
- ],
- fieldProps: {
- clearable: true,
- style: { width: "100%" },
- props: { checkStrictly: true }
- }
- }
- ];
- const tableColums: PlusColumn[] = [
- {
- label: "名称",
- prop: "name",
- disabledHeaderFilter: true,
- tooltip: "名称",
- tableColumnProps: {
- align: "center",
- showOverflowTooltip: true
- }
- },
- {
- label: "状态",
- prop: "status",
- valueType: "select",
- options: [
- {
- label: "未解决",
- value: "0",
- color: "red"
- },
- {
- label: "已解决",
- value: "1",
- color: "blue"
- },
- {
- label: "解决中",
- value: "2",
- color: "yellow"
- },
- {
- label: "失败",
- value: "3",
- color: "red"
- }
- ]
- },
- {
- label: "标签",
- prop: "tag",
- valueType: "tag",
- fieldProps: (value: string) => {
- return { type: value };
- }
- },
- {
- label: "时间",
- prop: "time",
- valueType: "date-picker",
- tableColumnProps: {
- align: "center",
- sortable: true
- }
- }
- ];
- const multipleSelection = ref<TableRow[]>([]);
- const TestServe = {
- getList: async () => {
- const data = Array.from({ length: 4 }).map((item, index) => {
- return {
- id: index,
- name: index === 0 ? index + "name".repeat(100) : index + "name",
- status: String(index % 3),
- tag:
- index === 1
- ? "success"
- : index === 2
- ? "warning"
- : index === 3
- ? "info"
- : "danger",
- time: new Date()
- };
- });
- return {
- data: data as TableRow[]
- };
- }
- };
- const getList = async () => {
- try {
- const { data } = await TestServe.getList();
- tableData.value = data;
- } catch (error) {}
- };
- buttons.value = [
- {
- // 查看
- text: "查看",
- code: "view",
- props: (row: any) => ({
- type: "info",
- disabled: row.status === "1"
- }),
- show: (row: any) => row.status === "1"
- },
- {
- // 修改
- text: "修改",
- code: "edit",
- // props v0.1.16 版本新增函数类型
- props: (row: any) => ({
- type: "primary",
- disabled: row.status === "1"
- }),
- show: computed(() => true)
- },
- {
- // 删除
- text: "删除",
- code: "delete",
- // props v0.1.16 版本新增计算属性支持
- props: computed(() => ({ type: "danger" })),
- confirm: {
- options: {
- draggable: true,
- message: "确定删除此数据吗?"
- }
- }
- }
- ];
- getList();
- const handleChange = (values: any) => {
- console.log(values, "change");
- };
- const handleSearch = (values: any) => {
- console.log(values, "search");
- };
- const handleRest = () => {
- console.log("handleRest");
- };
- const handlePaginationChange = (_pageInfo: PageInfo): void => {
- console.log("handlePaginationChange", _pageInfo);
- pageInfo.value = _pageInfo;
- getList();
- };
- const handleSelectionChange = (val: TableRow[]) => {
- multipleSelection.value = val;
- console.log("handleSelectionChange", val);
- };
- const handleSrotChange = (values: any) => {
- console.log("handleSrotChange", values);
- };
- const handleClickButton = (data: ButtonsCallBackParams) => {
- console.log("handleClickButton", data);
- };
- </script>
- <template>
- <div class="p-0">
- <el-card class="box-card">
- <PlusSearch
- v-model="state"
- :columns="columns"
- :show-number="2"
- label-width="80"
- label-position="right"
- @change="handleChange"
- @search="handleSearch"
- @reset="handleRest"
- />
- </el-card>
- <el-card class="mt-5">
- <PlusTable
- :columns="tableColums"
- :table-data="tableData"
- :is-selection="true"
- :action-bar="{
- buttons: buttons,
- type: 'button',
- width: 260
- }"
- :pagination="{
- total: 100,
- modelValue: pageInfo,
- pageSizeList: [10, 20, 50]
- }"
- :adaptive="{ offsetBottom: 50 }"
- @selection-change="handleSelectionChange"
- @paginationChange="handlePaginationChange"
- @sort-change="handleSrotChange"
- @clickAction="handleClickButton"
- />
- </el-card>
- </div>
- </template>
- <style scoped lang="scss"></style>
|