123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <template>
- <div class="box-container">
- <!-- <Banner /> -->
- <div class="content">
- <byTable
- ref="singleTable"
- :source="sourceList.data"
- :pagination="sourceList.pagination"
- :config="config"
- :loading="loading"
- :height="tableHeight"
- highlight-current-row
- :selectConfig="selectConfig"
- :table-events="{
- //element talbe事件都能传
- 'row-click': handleRowClick,
- 'cell-contextmenu': handleRowClick.apply,
- 'select-all': select,
- }"
- :action-list="[
- {
- text: '新建合同',
- plain: true,
- type: 'warning',
- action: () => openModal('add'),
- },
- ]"
- @get-list="getList"
- >
- <template #slotName="{ item }">
- {{ item.createTime }}
- </template>
- </byTable>
- </div>
- <el-dialog
- :title="modalType == 'add' ? '新增' : '编辑'"
- v-model="dialogVisible"
- width="500"
- :before-close="handleClose"
- >
- <byForm
- :formConfig="formConfig"
- :formOption="formOption"
- v-model="formData"
- >
- <template #slot> 可自定义所需功能 </template>
- </byForm>
- <template #footer>
- <span class="dialog-footer">
- <el-button @click="dialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="dialogVisible = false"
- >确 定</el-button
- >
- </span>
- </template>
- </el-dialog>
- </div>
- </template>
-
- <script setup>
- /* eslint-disable vue/no-unused-components */
- import { ElMessage, ElMessageBox } from "element-plus";
- import byTable from "@/components/byTable/index";
- import byForm from "@/components/byForm/index";
- import { computed, defineComponent, ref } from "vue";
- const loading = ref(false);
- const fixedRight = ref("right");
- const align = ref("center");
- const tableHeight = ref(null);
- const border = ref(true);
- const sourceList = ref({
- data: [],
- pagination: {
- total: 3,
- pageNum: 1,
- pageSize: 10,
- },
- });
- const singleTable = ref({});
- const dialogVisible = ref(false);
- const modalType = ref("add");
- const { proxy } = getCurrentInstance();
- const selectConfig = computed(() => {
- return [
- {
- label: "合同状态1",
- prop: "tdaProductId",
- data: [
- {
- label: "已关闭",
- value: "123",
- },
- ],
- },
- {
- label: "合同状态22",
- prop: "tdaApplicationId",
- data: [
- {
- label: "已关闭",
- value: "123",
- },
- ],
- },
- ];
- });
- const config = computed(() => {
- return [
- {
- type: "selection",
- attrs: {
- checkAtt: "isCheck",
- },
- },
- {
- attrs: {
- label: "权限字符",
- prop: "roleKey",
- },
- },
- {
- attrs: {
- label: "显示顺序",
- prop: "dataScope",
- align: "center",
- width: 200,
- },
- // 渲染字符串,默认不想展示 prop 的值,而是想对它做一些处理的时候,可以用这个方法
- render(isForbid) {
- return isForbid ? "禁用中" : "非禁用";
- },
- },
- {
- attrs: {
- label: "状态",
- align: align.value,
- width: 100,
- click: (items) => {
- console.log(items);
- },
- },
- // 渲染组件,返回值为一个数组, data 作为组件的 v-model,适用于需要展示复杂的数据的场景
- renderComponent(row) {
- return [
- {
- name: "el-switch",
- data: row.menuCheckStrictly,
- change: (e) => {
- console.log(e, "change事件");
- },
- click: (e) => {
- console.log(e, "click事件");
- },
- },
- ];
- },
- },
- {
- attrs: {
- label: "创建时间",
- align: align.value,
- width: 200,
- prop: "createTime",
- slot: "slotName",
- },
- },
- {
- attrs: {
- label: "操作",
- width: "400",
- align: align.value,
- // 设置当前列恢复点击事件冒泡
- // isBubble: false,
- fixed: fixedRight.value,
- },
- // 渲染 el-button,一般用在最后一列。
- renderHTML(row) {
- return [
- {
- attrs: {
- label: "修改",
- type: "primary",
- text: true,
- bg: true,
- },
- el: "button",
- click() {
- ElMessage({
- message: JSON.stringify(row),
- });
- },
- },
- {
- attrs: {
- label: "删除",
- type: "danger",
- text: true,
- bg: true,
- },
- el: "button",
- click() {
- ElMessage({
- message: `编号${row.id} router -> 已跳转到编辑页面!`,
- });
- },
- },
- // {
- // attrs: {
- // label: '发布',
- // type: 'primary',
- // text: true,
- // bg: true,
- // },
- // el: 'button',
- // click() {
- // setPublish(row)
- // },
- // },
- // !row.isForbid
- // ? {
- // attrs: {
- // label: '三元写法ture',
- // type: 'primary',
- // text: true,
- // bg: true,
- // disabled: false,
- // },
- // el: 'button',
- // click() {
- // setForbid(row)
- // },
- // }
- // : {
- // attrs: {
- // label: '三元写法false',
- // text: true,
- // bg: true,
- // type: 'primary',
- // disabled: false,
- // style: {
- // color: '#e6a23c',
- // },
- // },
- // el: 'button',
- // click() {
- // setForbid(row)
- // },
- // },
- ];
- },
- },
- ];
- });
- const formData = reactive({});
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- rules: [],
- });
- const formConfig = computed(() => {
- return [
- {
- type: "input",
- prop: "name",
- label: "label名称",
- required: true,
- itemWidth: 100,
- //disabled:true,
- itemType: "textarea",
- },
- {
- type: "select",
- prop: "xiala",
- label: "下拉框",
- multiple: true,
- style: {
- width: "300px",
- },
- isLoad: {
- url: "/getRouters",
- resUrl: "data",
- //如果接口回来为stringArray,可以把labelkey和labelval都设置为stringArray
- labelKey: "name",
- labelVal: "path",
- },
- //所有组件的change事件监听
- fn: (e) => {
- console.log(e);
- },
- },
- {
- type: "date",
- prop: "date",
- label: "时间",
- itemType: "date",
- },
- {
- type: "radio",
- prop: "radio",
- label: "单选",
- },
- {
- type: "slot",
- slotName: "slot",
- label: "插槽",
- },
- {
- type: "selectInput",
- label: "交易金额",
- itemWidth: 60,
- data:[],
- placeholder: "请输入",
- selectPlaceholder: "币种",
- selectProp: "currency",
- isLoad: {
- url: "/supplierInfo/page",
- req: {
- pageNum: 1,
- pageSize: 9999,
- },
- labelKey: "name",
- labelVal: "id",
- method: "post",
- resUrl: "rows",
- },
- },
- {
- //使用此功能需要初始化prop数据至少是对象
- type: "json",
- prop: "standardJson",
- json: [
- {
- type: "input",
- prop: "englishName",
- label: "英文名",
- },
- {
- type: "input",
- prop: "code",
- label: "备注",
- },
- {
- type: "input",
- prop: "netWeight",
- label: "净重",
- },
- {
- type: "input",
- prop: "customhouse",
- label: "海关编码",
- },
- ],
- },
- ];
- });
- const sleep = (time = 1000) => {
- return new Promise((resolve) => setTimeout(resolve, time));
- };
- const getList = async (res) => {
- console.log(sourceList.value);
- console.log({ ...sourceList.value.pagination, ...res });
- loading.value = true;
- proxy.get("/system/role/list?pageNum=1&pageSize=10").then((message) => {
- console.log(message);
- sourceList.value.data = message.rows;
- setTimeout(() => {
- loading.value = false;
- }, 200);
- });
- };
- const openModal = () => {
- dialogVisible.value = true;
- };
- const select = (row, column, cell) => {
- ElMessage({
- dangerouslyUseHTMLString: true, // Be careful :)
- message: `点了全选`,
- });
- };
- const handleRowClick = (row, column, cell) => {
- ElMessage({
- dangerouslyUseHTMLString: true, // Be careful :)
- message: `row-click 事件,单击了<span style="color: red;"> 第${row.$index}行 </span>请看控制台 log`,
- });
- console.log("回调参数分别为: row, column, cell");
- console.log(row, column, cell);
- };
- const setPublish = (row) => {
- ElMessageBox.confirm(
- `此操作会将${row.name}发布到线上, 是否继续?`,
- `编号${row.id}提示`,
- {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }
- )
- .then(() => {
- ElMessage({
- type: "success",
- message: "发布成功!",
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "已取消发布",
- });
- });
- };
- const setForbid = async (row) => {
- loading.value = true;
- await sleep();
- loading.value = false;
- row.isForbid = !row.isForbid;
- };
- const copyLink = (row) => {
- ElMessage({
- type: "success",
- message: "指令测试-复制成功,可以粘贴啦!",
- });
- };
- getList();
- </script>
-
- <style lang="scss" scoped>
- .box-container {
- .content {
- position: relative;
- margin: 0 auto;
- }
- }
- </style>
|