demo.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. type: "selectInput",
  309. label: "交易金额",
  310. itemWidth: 60,
  311. data:[],
  312. placeholder: "请输入",
  313. selectPlaceholder: "币种",
  314. selectProp: "currency",
  315. isLoad: {
  316. url: "/supplierInfo/page",
  317. req: {
  318. pageNum: 1,
  319. pageSize: 9999,
  320. },
  321. labelKey: "name",
  322. labelVal: "id",
  323. method: "post",
  324. resUrl: "rows",
  325. },
  326. },
  327. {
  328. //使用此功能需要初始化prop数据至少是对象
  329. type: "json",
  330. prop: "standardJson",
  331. json: [
  332. {
  333. type: "input",
  334. prop: "englishName",
  335. label: "英文名",
  336. },
  337. {
  338. type: "input",
  339. prop: "code",
  340. label: "备注",
  341. },
  342. {
  343. type: "input",
  344. prop: "netWeight",
  345. label: "净重",
  346. },
  347. {
  348. type: "input",
  349. prop: "customhouse",
  350. label: "海关编码",
  351. },
  352. ],
  353. },
  354. ];
  355. });
  356. const sleep = (time = 1000) => {
  357. return new Promise((resolve) => setTimeout(resolve, time));
  358. };
  359. const getList = async (res) => {
  360. console.log(sourceList.value);
  361. console.log({ ...sourceList.value.pagination, ...res });
  362. loading.value = true;
  363. proxy.get("/system/role/list?pageNum=1&pageSize=10").then((message) => {
  364. console.log(message);
  365. sourceList.value.data = message.rows;
  366. setTimeout(() => {
  367. loading.value = false;
  368. }, 200);
  369. });
  370. };
  371. const openModal = () => {
  372. dialogVisible.value = true;
  373. };
  374. const select = (row, column, cell) => {
  375. ElMessage({
  376. dangerouslyUseHTMLString: true, // Be careful :)
  377. message: `点了全选`,
  378. });
  379. };
  380. const handleRowClick = (row, column, cell) => {
  381. ElMessage({
  382. dangerouslyUseHTMLString: true, // Be careful :)
  383. message: `row-click 事件,单击了<span style="color: red;"> 第${row.$index}行 </span>请看控制台 log`,
  384. });
  385. console.log("回调参数分别为: row, column, cell");
  386. console.log(row, column, cell);
  387. };
  388. const setPublish = (row) => {
  389. ElMessageBox.confirm(
  390. `此操作会将${row.name}发布到线上, 是否继续?`,
  391. `编号${row.id}提示`,
  392. {
  393. confirmButtonText: "确定",
  394. cancelButtonText: "取消",
  395. type: "warning",
  396. }
  397. )
  398. .then(() => {
  399. ElMessage({
  400. type: "success",
  401. message: "发布成功!",
  402. });
  403. })
  404. .catch(() => {
  405. ElMessage({
  406. type: "info",
  407. message: "已取消发布",
  408. });
  409. });
  410. };
  411. const setForbid = async (row) => {
  412. loading.value = true;
  413. await sleep();
  414. loading.value = false;
  415. row.isForbid = !row.isForbid;
  416. };
  417. const copyLink = (row) => {
  418. ElMessage({
  419. type: "success",
  420. message: "指令测试-复制成功,可以粘贴啦!",
  421. });
  422. };
  423. getList();
  424. </script>
  425. <style lang="scss" scoped>
  426. .box-container {
  427. .content {
  428. position: relative;
  429. margin: 0 auto;
  430. }
  431. }
  432. </style>