You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

705 lines
22 KiB

3 years ago
<template>
3 years ago
<div>
3 years ago
<!-- 查询配置 -->
<div>
<div ref="lxHeader">
3 years ago
<LxHeader
3 years ago
:icon="$route.meta.icon"
3 years ago
:text="$route.meta.title"
3 years ago
style="margin-bottom: 10px; border: 0px; margin-top: 15px"
>
3 years ago
<div slot="content"></div>
<slot>
3 years ago
<header-content :auths="auths_auth_mixin">
<template #search>
<div style="display: flex">
3 years ago
<Select
v-model="select.filter[0].key"
style="width: 100px"
placeholder="搜索条目"
>
<Option
v-for="item in form"
:key="item.id"
:value="item.field"
3 years ago
>{{ item.name }}</Option
3 years ago
>
3 years ago
</Select>
3 years ago
<Select
v-model="select.filter[0].op"
style="width: 100px; margin-left: 10px"
placeholder="搜索条件"
>
<Option
v-for="item in op"
:key="item.value"
:value="item.value"
3 years ago
>{{ item.label }}</Option
3 years ago
>
3 years ago
</Select>
3 years ago
<template
v-if="
select.filter[0].op !== 'range' &&
!columnArrTest(select.filter[0].key)
"
>
<Input
v-model="select.filter[0].value"
style="width: 150px; margin-left: 10px"
placeholder="请填写关键词"
/>
3 years ago
</template>
3 years ago
<template
v-else-if="
select.filter[0].op !== 'range' &&
columnArrTest(select.filter[0].key)
"
>
<Select
v-model="select.filter[0].value"
style="width: 150px; margin-left: 10px"
placeholder="请选择关键词"
>
<Option
v-for="item in getColumnParams(select.filter[0].key)"
:key="item.id"
3 years ago
:value="getColumnField(select.filter[0].key)._relations ? item[getColumnField(select.filter[0].key)._relations.foreign_key] : item.value"
3 years ago
>{{
3 years ago
item.key || item.value || item.name || item.no || item.mingcheng || item.id
3 years ago
}}</Option
>
3 years ago
</Select>
</template>
<template v-else>
3 years ago
<Input
:value="select.filter[0].value.split(',')[0]"
style="width: 150px; margin-left: 10px"
placeholder="范围开始关键词"
@input="(e) => inputStartHandler(e, select.filter[0])"
/>
<span
style="
margin-left: 10px;
display: flex;
align-items: center;
"
3 years ago
></span
3 years ago
>
<Input
:value="select.filter[0].value.split(',')[1]"
style="width: 150px; margin-left: 10px"
placeholder="范围结束关键词"
@input="(e) => inputEndHandler(e, select.filter[0])"
/>
3 years ago
</template>
<Button
style="margin-left: 10px"
type="primary"
@click="$refs['xyTable'].getTableData(true)"
3 years ago
>查询</Button
3 years ago
>
<xy-selectors
style="margin-left: 10px"
@reset="reset"
@search="$refs['xyTable'].getTableData(true)"
>
<template>
<div class="select">
3 years ago
<div
class="select__item"
v-for="(item, index) in select.filter"
:key="`${item.value}-${index}`"
>
<p>条件{{ index + 1 }}</p>
<Select
v-model="item.key"
style="width: 100px"
placeholder="搜索条目"
>
<Option
v-for="item in form"
:key="item.id"
:value="item.field"
3 years ago
>{{ item.name }}</Option
3 years ago
>
3 years ago
</Select>
3 years ago
<Select
v-model="item.op"
style="width: 100px; margin-left: 10px"
placeholder="搜索条件"
>
<Option
v-for="item in op"
:key="item.value"
:value="item.value"
3 years ago
>{{ item.label }}</Option
3 years ago
>
3 years ago
</Select>
3 years ago
<template
v-if="
item.op !== 'range' && !columnArrTest(item.key)
"
>
<Input
v-model="item.value"
style="width: 150px; margin-left: 10px"
placeholder="请填写关键词"
/>
3 years ago
</template>
3 years ago
<template
v-else-if="
item.op !== 'range' && columnArrTest(item.key)
"
>
<Select
v-model="item.value"
style="width: 150px; margin-left: 10px"
placeholder="请选择关键词"
>
<Option
v-for="item in getColumnParams(item.key)"
:key="item.id"
3 years ago
:value="getColumnField(item.key)._relations ? item[getColumnField(item.key)._relations.foreign_key] : item.value"
3 years ago
>{{
3 years ago
item.key || item.value || item.name || item.no || item.mingcheng || item.id
3 years ago
}}</Option
>
3 years ago
</Select>
</template>
<template v-else>
3 years ago
<Input
:value="item.value.split(',')[0]"
style="width: 150px; margin-left: 10px"
placeholder="范围开始关键词"
@input="(e) => inputStartHandler(e, item)"
/>
<span style="margin-left: 10px"></span>
<Input
:value="item.value.split(',')[1]"
style="width: 150px; margin-left: 10px"
placeholder="范围结束关键词"
@input="(e) => inputEndHandler(e, item)"
/>
3 years ago
</template>
3 years ago
<el-button
v-if="index !== 0"
size="small"
type="danger"
icon="el-icon-delete"
circle
style="margin-left: 10px"
@click="select.filter.splice(index, 1)"
></el-button>
3 years ago
</div>
</div>
<div class="add-btn">
3 years ago
<el-button
size="small"
type="primary"
icon="el-icon-plus"
circle
@click="
select.filter.push({ key: '', op: '', value: '' })
"
></el-button>
3 years ago
<span>新增一条</span>
</div>
</template>
</xy-selectors>
</div>
</template>
<template #create>
<Button
type="primary"
3 years ago
@click="
$refs['dialog'].setType('add'), $refs['dialog'].show()
"
3 years ago
>新增</Button
3 years ago
>
</template>
3 years ago
<template #import>
3 years ago
<Button type="primary" @click="$refs['imports'].show()"
3 years ago
>导入</Button
3 years ago
>
</template>
3 years ago
<template #export>
<Button
type="primary"
3 years ago
@click="exportExcel(new Date().getTime().toString())"
3 years ago
>导出</Button
3 years ago
>
</template>
</header-content>
3 years ago
</slot>
</LxHeader>
</div>
</div>
<xy-table
3 years ago
:btn-width="300"
3 years ago
:auths="auths_auth_mixin"
:delay-req="true"
:destroy-action="destroy"
3 years ago
ref="xyTable"
:border="true"
3 years ago
:action="index"
3 years ago
:req-opt="select"
3 years ago
:destroy-req-opt="select"
:table-item="table"
3 years ago
@detail="
(row) => {
3 years ago
$router.push({
3 years ago
path: $route.path + '/detail/' + row.id
3 years ago
})
3 years ago
}
"
@editor="
(row) => {
$refs['dialog'].setId(row.id);
$refs['dialog'].setType('editor');
$refs['dialog'].show();
}
"
2 years ago
@loaded="adjustAlignment"
3 years ago
>
3 years ago
<template #assetsHistory="{row}">
3 years ago
<Button
size="small"
type="primary"
3 years ago
@click="$refs['assetsHistoryList'].setId(row.id),$refs['assetsHistoryList'].show()"
3 years ago
>历史</Button
>
</template>
3 years ago
<template #picture="{row}">
<Button
size="small"
type="primary"
@click="$refs['atlas'].setId(row.id),$refs['atlas'].show()"
>图集</Button
>
</template>
3 years ago
</xy-table>
3 years ago
<dialoger
:table-name="customForm.tableName"
:form-info="form"
ref="dialog"
@refresh="$refs['xyTable'].getTableData()"
>
</dialoger>
<drawer
:table-name="customForm.tableName"
:form-info="form"
ref="drawer"
></drawer>
<imports
:table-name="customForm.tableName"
:form-info="form"
ref="imports"
@refresh="$refs['xyTable'].getTableData()"
></imports>
3 years ago
<atlas ref="atlas"></atlas>
3 years ago
<assetsHistoryList ref="assetsHistoryList"></assetsHistoryList>
3 years ago
</div>
</template>
<script>
3 years ago
import { index as fieldIndex } from "@/api/system/customFormField";
3 years ago
import { authMixin } from "@/mixin/authMixin";
3 years ago
import { index, destroy } from "@/api/system/baseForm";
3 years ago
import { op } from "@/const/op";
import { download } from "@/utils/downloadRequest";
import { getparameter } from "@/api/system/dictionary";
3 years ago
import { show } from "@/api/system/customForm";
3 years ago
import * as XLSX from "xlsx";
import { saveAs } from "file-saver";
3 years ago
import { listdept } from "@/api/system/department"
3 years ago
3 years ago
import dialoger from "./dialog.vue";
3 years ago
import LxHeader from "@/components/LxHeader/index.vue";
3 years ago
import headerContent from "@/components/LxHeader/XyContent.vue";
import drawer from "@/views/component/drawer.vue";
3 years ago
import imports from "./imports.vue";
3 years ago
import atlas from "@/views/assets/atlas.vue";
3 years ago
import assetsHistoryList from '@/views/assets/assetsHistoryList.vue'
3 years ago
export default {
3 years ago
name: 'tableList',
3 years ago
components: {
3 years ago
LxHeader,
dialoger,
headerContent,
drawer,
3 years ago
imports,
3 years ago
3 years ago
atlas,
assetsHistoryList
3 years ago
},
3 years ago
mixins: [authMixin],
3 years ago
provide: {
formStore: () => this.form,
},
3 years ago
data() {
return {
2 years ago
firstAdjustTable: true,
3 years ago
op,
select: {
table_name: "",
filter: [
{
key: "",
op: "",
3 years ago
value: "",
},
],
3 years ago
},
3 years ago
form: [],
table: [],
customForm: {
customFormId: "",
3 years ago
tableName: "",
},
};
3 years ago
},
methods: {
3 years ago
index,
destroy,
download,
3 years ago
reset() {
3 years ago
this.select.filter.splice(1);
3 years ago
this.select.filter[0] = {
key: "",
op: "",
3 years ago
value: "",
};
3 years ago
},
3 years ago
async exportExcel(sheetName) {
3 years ago
const res = await index(
Object.assign(this.select, { page: 1, page_size: 9999 })
);
if (res.data) {
let headers = this.form.map((i) => {
3 years ago
return {
key: i.field,
3 years ago
title: i.name,
};
});
const data = res.data.map((row) =>
headers.map((header) => row[header.key])
);
data.unshift(headers.map((header) => header.title));
3 years ago
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, sheetName);
3 years ago
const wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
`${sheetName}.xlsx`
);
3 years ago
}
},
3 years ago
//target要为内存地址引用类型
3 years ago
inputStartHandler(e, target) {
let temp = target?.value.split(",")[1];
target.value = `${e},${temp ? temp : ""}`;
3 years ago
},
3 years ago
inputEndHandler(e, target) {
let temp = target?.value.split(",")[0];
target.value = `${temp ? temp : ""},${e}`;
3 years ago
},
3 years ago
async getFormDetail() {
3 years ago
if (this.$route.meta.params?.custom_form) {
let decode = decodeURIComponent(this.$route.meta.params?.custom_form);
3 years ago
try {
3 years ago
let custom_form = JSON.parse(decode);
this.customForm.customFormId = custom_form.custom_form_id;
this.customForm.tableName = custom_form.table_name;
this.select.table_name = custom_form.table_name;
} catch (err) {
console.warn(err);
3 years ago
}
}
3 years ago
const res = await show({ id: this.customForm.customFormId }, false);
//字段处理
3 years ago
//初始表白名单
let baseTable = new Map([
['departments', async () => {
const res = await listdept()
return res
}],
['admins',[]]
])
3 years ago
let { fields, relation } = res;
3 years ago
let fieldRes = fields.sort((a,b) => a.sort - b.sort)
3 years ago
if (
!fields ||
!relation ||
!fields instanceof Array ||
!relation instanceof Array
) {
throw new Error("fields或relation格式错误");
3 years ago
}
3 years ago
console.log(fieldRes)
fieldRes?.forEach((i, index) => {
3 years ago
i._relations = relation.find(
(j) => j.link_table_name.split("_")[1] === i.field
3 years ago
) || relation.find(
(j) => j.local_key === i.field
3 years ago
);
if (i.select_item && typeof i.select_item === "object") {
let keys = Object.keys(i.select_item);
3 years ago
if (keys.length > 0) {
i._params = keys.map((key) => {
return {
key,
value: /^\d*$/.test(i.select_item[key])
? Number(i.select_item[key])
: i.select_item[key],
};
});
}
3 years ago
}
3 years ago
if (i.edit_input === 'file' || i.edit_input === 'files') {
return
}
3 years ago
if (i._relations) {
3 years ago
if (baseTable.get(i._relations.link_table_name)) {
3 years ago
baseTable
.get(i._relations.link_table_name)()
.then((res) => {
i._params = res.data;
});
3 years ago
} else {
i._params = i._relations.parameter_id
3 years ago
? getparameter({ id: i._relations.parameter_id }, false).then(
(res) => {
i._params = res.detail;
}
)
3 years ago
: this.index({
table_name: i._relations.link_table_name,
page: 1,
page_size: 9999,
}).then((res) => {
i._params = res.data;
});
}
3 years ago
}
3 years ago
});
3 years ago
this.form = fieldRes || [];
this.form
3 years ago
?.filter((i) => i.list_show)
3 years ago
.forEach((i) => {
3 years ago
let linkOb = {};
3 years ago
3 years ago
if (i.edit_input === "richtext") {
linkOb.customFn = (row) => {
3 years ago
return (
3 years ago
<div
style={{ "max-height": "55px","overflow": "scroll" }}
domPropsInnerHTML={row[i.field]}
></div>
);
};
}
if (
i.select_item &&
typeof i.select_item === "object" &&
!(i.select_item instanceof Array)
) {
let keys = Object.keys(i.select_item);
linkOb.customFn = (row) => {
let paramMap = new Map();
keys.forEach((key) => {
paramMap.set(i.select_item[key], key);
});
3 years ago
return <span>{ paramMap.get(row[i.field]) ? paramMap.get(row[i.field].toString()) : row[i.field] }</span>;
3 years ago
};
3 years ago
}
3 years ago
if (i._relations) {
3 years ago
let { link_relation, foreign_key, link_with_name } = i._relations;
if (link_relation === "newHasOne" || link_relation === "hasOne") {
linkOb.customFn = (row) => {
3 years ago
if (i.edit_input === "file") {
return (
<a
3 years ago
download={row[link_with_name]?.original_name}
href={row[link_with_name]?.url}
3 years ago
>
3 years ago
{row[link_with_name]?.original_name}
3 years ago
</a>
);
} else {
return (
<span>
3 years ago
{row[link_with_name]?.name ||
3 years ago
row[link_with_name]?.no ||
3 years ago
row[link_with_name]?.value}
3 years ago
</span>
);
}
3 years ago
};
3 years ago
}
3 years ago
3 years ago
if (link_relation === "hasMany" || link_relation === "newHasMany") {
3 years ago
linkOb.customFn = (row) => {
3 years ago
if (i.edit_input === "files") {
return (
<div style="display: flex;flex-direction: column;">
{row[link_with_name]?.map((o) => (
<a>
{ o?.original_name || o?.name }
</a>
))}
</div>
)
} else {
return (
<div>
{row[link_with_name]?.map((o) => (
<p>
{o?.name ||
o?.no ||
o?.value ||
o?.biaoti ||
o?.mingcheng}
</p>
))}
</div>
);
}
3 years ago
};
3 years ago
}
}
3 years ago
3 years ago
this.table.push(
Object.assign(
{
prop: i.field,
label: i.name,
width: i.width,
2 years ago
align: 'center',
3 years ago
fixed: i.is_fixed,
},
linkOb
)
3 years ago
);
});
3 years ago
this.table.unshift({
2 years ago
prop: "id",
3 years ago
width: 60,
3 years ago
label: "序号",
});
},
2 years ago
adjustAlignment () {
if (this.firstAdjustTable) {
const data = this.$refs['xyTable'].getListData();
2 years ago
if (data.length < 2) return;
try {
this.form.filter(i => i.list_show).forEach((i) => {
let lengthTemp;
let temp = 0;
while (!lengthTemp || temp < data.length) {
lengthTemp = data[temp][i.field]?.length??0;
temp++;
2 years ago
}
2 years ago
for (let j = 0;j < data.length;j++) {
if (/^-?\d+\.\d+/.test(data[j][i.field])) {
this.table.find(a => a.prop === i.field).align = 'right';
return
}
if (Math.abs(lengthTemp - (data[j][i.field]?.length)??0) > 4) {
this.table.find(a => a.prop === i.field).align = 'left';
return
}
2 years ago
}
2 years ago
})
} catch (e) {
}
2 years ago
this.$nextTick(() => {
this.$refs['xyTable'].doLayout();
this.firstAdjustTable = false;
})
}
}
3 years ago
},
3 years ago
3 years ago
computed: {
columnArrTest() {
return function (field) {
3 years ago
return this.form.find((i) => i.field === field)
3 years ago
? this.form.find((i) => i.field === field).search_input === "checkbox" || this.form.find((i) => i.field === field).search_input === "radio"
3 years ago
: false;
};
3 years ago
},
3 years ago
getColumnField() {
return function (field) {
return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field)
: {};
};
},
3 years ago
getColumnParams() {
return function (field) {
3 years ago
return this.form.find((i) => i.field === field)
3 years ago
? this.form.find((i) => i.field === field)._params
3 years ago
: [];
};
3 years ago
}
3 years ago
},
3 years ago
created() {
3 years ago
this.getFormDetail();
},
};
3 years ago
</script>
<style scoped lang="scss">
3 years ago
.select {
&__item {
& > p {
display: inline-block;
width: 80px;
text-align: center;
}
3 years ago
3 years ago
& + div {
margin-top: 6px;
}
}
}
.add-btn {
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
& > span {
padding: 0 10px;
}
}
3 years ago
a {
color: red;
text-decoration: none;
transition: all 0.2s;
}
a:hover {
color: red;
text-decoration: underline;
}
3 years ago
</style>