demo.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div class="box-container">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. ref="singleTable"
  7. :source="sourceList.data"
  8. :pagination="sourceList.pagination"
  9. :config="config"
  10. :loading="loading"
  11. :height="tableHeight"
  12. highlight-current-row
  13. :selectConfig="selectConfig"
  14. :table-events="{
  15. //element talbe事件都能传
  16. 'row-click': handleRowClick,
  17. 'cell-contextmenu': handleRowClick.apply,
  18. 'select-all': select,
  19. }"
  20. :action-list="[
  21. {
  22. text: '新建合同',
  23. plain: true,
  24. type: 'warning',
  25. action: () => openModal('add'),
  26. },
  27. ]"
  28. @get-list="getList"
  29. >
  30. <template #slotName="{ item }">
  31. {{ item.createTime }}
  32. </template>
  33. </byTable>
  34. </div>
  35. <el-dialog
  36. :title="modalType == 'add' ? '新增' : '编辑'"
  37. v-model="dialogVisible"
  38. width="500"
  39. :before-close="handleClose"
  40. >
  41. <byForm
  42. :formConfig="formConfig"
  43. :formOption="formOption"
  44. v-model="formData"
  45. >
  46. <template #slot> 可自定义所需功能 </template>
  47. </byForm>
  48. <template #footer>
  49. <span class="dialog-footer">
  50. <el-button @click="dialogVisible = false">取 消</el-button>
  51. <el-button type="primary" @click="dialogVisible = false"
  52. >确 定</el-button
  53. >
  54. </span>
  55. </template>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script setup>
  60. /* eslint-disable vue/no-unused-components */
  61. import { ElMessage, ElMessageBox } from "element-plus";
  62. import byTable from "@/components/byTable/index";
  63. import byForm from "@/components/byForm/index";
  64. import { computed, defineComponent, ref } from "vue";
  65. const loading = ref(false);
  66. const fixedRight = ref("right");
  67. const align = ref("center");
  68. const tableHeight = ref(null);
  69. const border = ref(true);
  70. const sourceList = ref({
  71. data: [],
  72. pagination: {
  73. total: 3,
  74. pageNum: 1,
  75. pageSize: 10,
  76. },
  77. });
  78. const singleTable = ref({});
  79. const dialogVisible = ref(false);
  80. const modalType = ref("add");
  81. const { proxy } = getCurrentInstance();
  82. const selectConfig = computed(() => {
  83. return [
  84. {
  85. label: "合同状态1",
  86. prop: "tdaProductId",
  87. data: [
  88. {
  89. label: "已关闭",
  90. value: "123",
  91. },
  92. ],
  93. },
  94. {
  95. label: "合同状态22",
  96. prop: "tdaApplicationId",
  97. data: [
  98. {
  99. label: "已关闭",
  100. value: "123",
  101. },
  102. ],
  103. },
  104. ];
  105. });
  106. const config = computed(() => {
  107. return [
  108. {
  109. type: "selection",
  110. attrs: {
  111. checkAtt: "isCheck",
  112. },
  113. },
  114. {
  115. attrs: {
  116. label: "权限字符",
  117. prop: "roleKey",
  118. },
  119. },
  120. {
  121. attrs: {
  122. label: "显示顺序",
  123. prop: "dataScope",
  124. align: "center",
  125. width: 200,
  126. },
  127. // 渲染字符串,默认不想展示 prop 的值,而是想对它做一些处理的时候,可以用这个方法
  128. render(isForbid) {
  129. return isForbid ? "禁用中" : "非禁用";
  130. },
  131. },
  132. {
  133. attrs: {
  134. label: "状态",
  135. align: align.value,
  136. width: 100,
  137. click: (items) => {
  138. console.log(items);
  139. },
  140. },
  141. // 渲染组件,返回值为一个数组, data 作为组件的 v-model,适用于需要展示复杂的数据的场景
  142. renderComponent(row) {
  143. return [
  144. {
  145. name: "el-switch",
  146. data: row.menuCheckStrictly,
  147. change: (e) => {
  148. console.log(e, "change事件");
  149. },
  150. click: (e) => {
  151. console.log(e, "click事件");
  152. },
  153. },
  154. ];
  155. },
  156. },
  157. {
  158. attrs: {
  159. label: "创建时间",
  160. align: align.value,
  161. width: 200,
  162. prop: "createTime",
  163. slot: "slotName",
  164. },
  165. },
  166. {
  167. attrs: {
  168. label: "操作",
  169. width: "400",
  170. align: align.value,
  171. // 设置当前列恢复点击事件冒泡
  172. // isBubble: false,
  173. fixed: fixedRight.value,
  174. },
  175. // 渲染 el-button,一般用在最后一列。
  176. renderHTML(row) {
  177. return [
  178. {
  179. attrs: {
  180. label: "修改",
  181. type: "primary",
  182. text: true,
  183. bg: true,
  184. },
  185. el: "button",
  186. click() {
  187. ElMessage({
  188. message: JSON.stringify(row),
  189. });
  190. },
  191. },
  192. {
  193. attrs: {
  194. label: "删除",
  195. type: "danger",
  196. text: true,
  197. bg: true,
  198. },
  199. el: "button",
  200. click() {
  201. ElMessage({
  202. message: `编号${row.id} router -> 已跳转到编辑页面!`,
  203. });
  204. },
  205. },
  206. // {
  207. // attrs: {
  208. // label: '发布',
  209. // type: 'primary',
  210. // text: true,
  211. // bg: true,
  212. // },
  213. // el: 'button',
  214. // click() {
  215. // setPublish(row)
  216. // },
  217. // },
  218. // !row.isForbid
  219. // ? {
  220. // attrs: {
  221. // label: '三元写法ture',
  222. // type: 'primary',
  223. // text: true,
  224. // bg: true,
  225. // disabled: false,
  226. // },
  227. // el: 'button',
  228. // click() {
  229. // setForbid(row)
  230. // },
  231. // }
  232. // : {
  233. // attrs: {
  234. // label: '三元写法false',
  235. // text: true,
  236. // bg: true,
  237. // type: 'primary',
  238. // disabled: false,
  239. // style: {
  240. // color: '#e6a23c',
  241. // },
  242. // },
  243. // el: 'button',
  244. // click() {
  245. // setForbid(row)
  246. // },
  247. // },
  248. ];
  249. },
  250. },
  251. ];
  252. });
  253. const formData = reactive({});
  254. const formOption = reactive({
  255. inline: true,
  256. labelWidth: 100,
  257. itemWidth: 100,
  258. rules: [],
  259. });
  260. const formConfig = computed(() => {
  261. return [
  262. {
  263. type: "input",
  264. prop: "name",
  265. label: "label名称",
  266. required: true,
  267. itemWidth: 100,
  268. //disabled:true,
  269. itemType: "textarea",
  270. },
  271. {
  272. type: "select",
  273. prop: "xiala",
  274. label: "下拉框",
  275. multiple: true,
  276. style: {
  277. width: "300px",
  278. },
  279. isLoad: {
  280. url: "/getRouters",
  281. resUrl: "data",
  282. //如果接口回来为stringArray,可以把labelkey和labelval都设置为stringArray
  283. labelKey: "name",
  284. labelVal: "path",
  285. },
  286. //所有组件的change事件监听
  287. fn: (e) => {
  288. console.log(e);
  289. },
  290. },
  291. {
  292. type: "date",
  293. prop: "date",
  294. label: "时间",
  295. itemType: "date",
  296. },
  297. {
  298. type: "radio",
  299. prop: "radio",
  300. label: "单选",
  301. },
  302. {
  303. type: "slot",
  304. slotName: "slot",
  305. label: "插槽",
  306. },
  307. {
  308. //使用此功能需要初始化prop数据至少是对象
  309. type: "json",
  310. prop: "standardJson",
  311. json: [
  312. {
  313. type: "input",
  314. prop: "englishName",
  315. label: "英文名",
  316. },
  317. {
  318. type: "input",
  319. prop: "code",
  320. label: "备注",
  321. },
  322. {
  323. type: "input",
  324. prop: "netWeight",
  325. label: "净重",
  326. },
  327. {
  328. type: "input",
  329. prop: "customhouse",
  330. label: "海关编码",
  331. },
  332. ],
  333. },
  334. ];
  335. });
  336. const sleep = (time = 1000) => {
  337. return new Promise((resolve) => setTimeout(resolve, time));
  338. };
  339. const getList = async (res) => {
  340. console.log(sourceList.value);
  341. console.log({ ...sourceList.value.pagination, ...res });
  342. loading.value = true;
  343. proxy.get("/system/role/list?pageNum=1&pageSize=10").then((message) => {
  344. console.log(message);
  345. sourceList.value.data = message.rows;
  346. setTimeout(() => {
  347. loading.value = false;
  348. }, 200);
  349. });
  350. };
  351. const openModal = () => {
  352. dialogVisible.value = true;
  353. };
  354. const select = (row, column, cell) => {
  355. ElMessage({
  356. dangerouslyUseHTMLString: true, // Be careful :)
  357. message: `点了全选`,
  358. });
  359. };
  360. const handleRowClick = (row, column, cell) => {
  361. ElMessage({
  362. dangerouslyUseHTMLString: true, // Be careful :)
  363. message: `row-click 事件,单击了<span style="color: red;"> 第${row.$index}行 </span>请看控制台 log`,
  364. });
  365. console.log("回调参数分别为: row, column, cell");
  366. console.log(row, column, cell);
  367. };
  368. const setPublish = (row) => {
  369. ElMessageBox.confirm(
  370. `此操作会将${row.name}发布到线上, 是否继续?`,
  371. `编号${row.id}提示`,
  372. {
  373. confirmButtonText: "确定",
  374. cancelButtonText: "取消",
  375. type: "warning",
  376. }
  377. )
  378. .then(() => {
  379. ElMessage({
  380. type: "success",
  381. message: "发布成功!",
  382. });
  383. })
  384. .catch(() => {
  385. ElMessage({
  386. type: "info",
  387. message: "已取消发布",
  388. });
  389. });
  390. };
  391. const setForbid = async (row) => {
  392. loading.value = true;
  393. await sleep();
  394. loading.value = false;
  395. row.isForbid = !row.isForbid;
  396. };
  397. const copyLink = (row) => {
  398. ElMessage({
  399. type: "success",
  400. message: "指令测试-复制成功,可以粘贴啦!",
  401. });
  402. };
  403. getList();
  404. </script>
  405. <style lang="scss" scoped>
  406. .box-container {
  407. .content {
  408. position: relative;
  409. margin: 0 auto;
  410. }
  411. }
  412. </style>