index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <script setup lang="ts">
  2. import { computed, ref } from "vue";
  3. import {
  4. type PlusColumn,
  5. useTable,
  6. PlusSearch,
  7. PlusTable,
  8. PageInfo,
  9. ButtonsCallBackParams
  10. } from "plus-pro-components";
  11. import { number } from "echarts";
  12. defineOptions({
  13. name: "SplitTable"
  14. });
  15. interface TableRow {
  16. id: number;
  17. name: string;
  18. status: string;
  19. tag: string;
  20. time: Date;
  21. }
  22. const state = ref({});
  23. const { tableData, buttons, pageInfo } = useTable<TableRow[]>();
  24. const columns: PlusColumn[] = [
  25. {
  26. label: "名称",
  27. prop: "name",
  28. valueType: "copy",
  29. tooltip: "名称最多显示6个字符"
  30. },
  31. {
  32. label: "状态",
  33. prop: "status",
  34. valueType: "select",
  35. options: [
  36. {
  37. label: "未解决",
  38. value: "0",
  39. color: "red"
  40. },
  41. {
  42. label: "已解决",
  43. value: "1",
  44. color: "blue"
  45. },
  46. {
  47. label: "解决中",
  48. value: "2",
  49. color: "yellow"
  50. },
  51. {
  52. label: "失败",
  53. value: "3",
  54. color: "red"
  55. }
  56. ]
  57. },
  58. {
  59. label: "时间",
  60. prop: "time",
  61. valueType: "date-picker"
  62. },
  63. {
  64. label: "数量",
  65. prop: "number",
  66. valueType: "input-number",
  67. fieldProps: { precision: 2, step: 2 }
  68. },
  69. {
  70. label: "城市",
  71. prop: "city",
  72. valueType: "cascader",
  73. options: [
  74. {
  75. value: "zhejiang",
  76. label: "浙江",
  77. children: [
  78. {
  79. value: "hangzhou",
  80. label: "杭州",
  81. children: [
  82. {
  83. value: "xihu",
  84. label: "西湖"
  85. }
  86. ]
  87. },
  88. {
  89. value: "ningbo",
  90. label: "宁波",
  91. children: [
  92. {
  93. value: "dongqianlake",
  94. label: "东钱湖"
  95. }
  96. ]
  97. }
  98. ]
  99. },
  100. {
  101. value: "jiangsu",
  102. label: "江苏",
  103. children: [
  104. {
  105. value: "nanjing",
  106. label: "南京",
  107. children: [
  108. {
  109. value: "zhonghuamen",
  110. label: "中华门"
  111. }
  112. ]
  113. }
  114. ]
  115. }
  116. ],
  117. fieldProps: {
  118. clearable: true,
  119. style: { width: "100%" },
  120. props: { checkStrictly: true }
  121. }
  122. }
  123. ];
  124. const tableColums: PlusColumn[] = [
  125. {
  126. label: "名称",
  127. prop: "name",
  128. disabledHeaderFilter: true,
  129. tooltip: "名称",
  130. tableColumnProps: {
  131. align: "center",
  132. showOverflowTooltip: true
  133. }
  134. },
  135. {
  136. label: "状态",
  137. prop: "status",
  138. valueType: "select",
  139. options: [
  140. {
  141. label: "未解决",
  142. value: "0",
  143. color: "red"
  144. },
  145. {
  146. label: "已解决",
  147. value: "1",
  148. color: "blue"
  149. },
  150. {
  151. label: "解决中",
  152. value: "2",
  153. color: "yellow"
  154. },
  155. {
  156. label: "失败",
  157. value: "3",
  158. color: "red"
  159. }
  160. ]
  161. },
  162. {
  163. label: "标签",
  164. prop: "tag",
  165. valueType: "tag",
  166. fieldProps: (value: string) => {
  167. return { type: value };
  168. }
  169. },
  170. {
  171. label: "时间",
  172. prop: "time",
  173. valueType: "date-picker",
  174. tableColumnProps: {
  175. align: "center",
  176. sortable: true
  177. }
  178. }
  179. ];
  180. const multipleSelection = ref<TableRow[]>([]);
  181. const TestServe = {
  182. getList: async () => {
  183. const data = Array.from({ length: 4 }).map((item, index) => {
  184. return {
  185. id: index,
  186. name: index === 0 ? index + "name".repeat(100) : index + "name",
  187. status: String(index % 3),
  188. tag:
  189. index === 1
  190. ? "success"
  191. : index === 2
  192. ? "warning"
  193. : index === 3
  194. ? "info"
  195. : "danger",
  196. time: new Date()
  197. };
  198. });
  199. return {
  200. data: data as TableRow[]
  201. };
  202. }
  203. };
  204. const getList = async () => {
  205. try {
  206. const { data } = await TestServe.getList();
  207. tableData.value = data;
  208. } catch (error) {}
  209. };
  210. buttons.value = [
  211. {
  212. // 查看
  213. text: "查看",
  214. code: "view",
  215. props: (row: any) => ({
  216. type: "info",
  217. disabled: row.status === "1"
  218. }),
  219. show: (row: any) => row.status === "1"
  220. },
  221. {
  222. // 修改
  223. text: "修改",
  224. code: "edit",
  225. // props v0.1.16 版本新增函数类型
  226. props: (row: any) => ({
  227. type: "primary",
  228. disabled: row.status === "1"
  229. }),
  230. show: computed(() => true)
  231. },
  232. {
  233. // 删除
  234. text: "删除",
  235. code: "delete",
  236. // props v0.1.16 版本新增计算属性支持
  237. props: computed(() => ({ type: "danger" })),
  238. confirm: {
  239. options: {
  240. draggable: true,
  241. message: "确定删除此数据吗?"
  242. }
  243. }
  244. }
  245. ];
  246. getList();
  247. const handleChange = (values: any) => {
  248. console.log(values, "change");
  249. };
  250. const handleSearch = (values: any) => {
  251. console.log(values, "search");
  252. };
  253. const handleRest = () => {
  254. console.log("handleRest");
  255. };
  256. const handlePaginationChange = (_pageInfo: PageInfo): void => {
  257. console.log("handlePaginationChange", _pageInfo);
  258. pageInfo.value = _pageInfo;
  259. getList();
  260. };
  261. const handleSelectionChange = (val: TableRow[]) => {
  262. multipleSelection.value = val;
  263. console.log("handleSelectionChange", val);
  264. };
  265. const handleSrotChange = (values: any) => {
  266. console.log("handleSrotChange", values);
  267. };
  268. const handleClickButton = (data: ButtonsCallBackParams) => {
  269. console.log("handleClickButton", data);
  270. };
  271. </script>
  272. <template>
  273. <div class="p-0">
  274. <el-card class="box-card">
  275. <PlusSearch
  276. v-model="state"
  277. :columns="columns"
  278. :show-number="2"
  279. label-width="80"
  280. label-position="right"
  281. @change="handleChange"
  282. @search="handleSearch"
  283. @reset="handleRest"
  284. />
  285. </el-card>
  286. <el-card class="mt-5">
  287. <PlusTable
  288. :columns="tableColums"
  289. :table-data="tableData"
  290. :is-selection="true"
  291. :action-bar="{
  292. buttons: buttons,
  293. type: 'button',
  294. width: 260
  295. }"
  296. :pagination="{
  297. total: 100,
  298. modelValue: pageInfo,
  299. pageSizeList: [10, 20, 50]
  300. }"
  301. :adaptive="{ offsetBottom: 50 }"
  302. @selection-change="handleSelectionChange"
  303. @paginationChange="handlePaginationChange"
  304. @sort-change="handleSrotChange"
  305. @clickAction="handleClickButton"
  306. />
  307. </el-card>
  308. </div>
  309. </template>
  310. <style scoped lang="scss"></style>