删除旧的代码

qianlishi 3 years ago
parent 2e24a4a4a7
commit 2175ca7b3a

@ -1,808 +0,0 @@
<template>
<div :class="[hasTreeFieldInQueryForm ? 'page-container' : 'app-container']">
<div v-if="hasTreeFieldInQueryForm" class="left-container">
<AnjiTree
ref="queryFormTree"
v-model.trim="queryParams[queryFormTreeField.field]"
:is-open="queryFormTreeField.anjiTreeOption.isOpen"
:enable-filter="queryFormTreeField.anjiTreeOption.enableFilter"
:label-name="queryFormTreeField.label"
:url="queryFormTreeField.anjiTreeOption.url"
@node-click="handleTreeNodeCheck"
/>
</div>
<div class="right-container">
<!-- 查询表单开始 -->
<el-form
ref="formSearch"
:model="queryParams"
label-width="100px"
v-permission="option.buttons.query.permission"
>
<el-row>
<el-col
v-for="(item, index) in queryFormFieldExcludeTree"
:key="item.field"
:span="queryFormFieldSpan(item)"
>
<el-form-item
v-if="index <= 2 || (index > 2 && queryParams.showMoreSearch)"
:label="item.label"
:rules="item.rules"
:prop="item.field"
>
<!-- 输入框 -->
<el-input
v-if="
item.inputType == 'input' || item.inputType == 'input-number'
"
v-model.trim="queryParams[item.field]"
:placeholder="item.placeholder || '请输入'"
:clearable="item.clearable !== false"
:disabled="item.disabled"
@change="value => queryFormChange(item.field, value)"
/>
<!-- 开关 -->
<el-switch
v-else-if="item.inputType == 'switch'"
v-model.trim="queryParams[item.field]"
:disabled="item.disabled"
:active-value="item.switchOption.disableValue"
:inactive-value="item.switchOption.enableValue"
active-color="#5887fb"
inactive-color="#ccc"
@change="value => queryFormChange(item.field, value)"
/>
<!-- 下拉框 -->
<anji-select
v-else-if="item.inputType == 'anji-select'"
v-model.trim="queryParams[item.field]"
:multiple="item.anjiSelectOption.multiple"
:dict-code="item.anjiSelectOption.dictCode"
:url="item.anjiSelectOption.url"
:method="item.anjiSelectOption.method"
:query-param="item.anjiSelectOption.queryParam"
:option="item.anjiSelectOption.option"
:label="item.anjiSelectOption.label"
:disabled-options="item.anjiSelectOption.disabledOptions"
:disabled="item.disabled"
:merge-label="item.anjiSelectOption.mergeLabel"
@change="value => queryFormChange(item.field, value)"
/>
<!-- 日期时间框 -->
<el-date-picker
v-else-if="item.inputType.indexOf('date') >= 0"
v-model="queryParams[item.field]"
style="width: 100%"
:placeholder="item.placeholder || '请选择'"
:type="item.inputType"
:clearable="item.clearable !== false"
@change="value => queryFormChange(item.field, value)"
/>
<!-- 待扩展的表单类型请自行扩展 -->
<el-input
v-else
placeholder="组件不支持此类型表单请至组件内部自行扩展"
disabled
/>
</el-form-item>
</el-col>
<el-col :span="6" style="text-align: center">
<el-button type="primary" @click="handleQueryForm('query')"
>查询</el-button
>
<el-button type="danger" @click="handleResetForm()"></el-button>
<a
v-if="queryFormFieldExcludeTree.length > 3"
style="margin-left: 8px"
@click="handleToggleMoreSearch"
>
{{ queryParams.showMoreSearch == true ? "收起" : "展开" }}
<i
:class="
queryParams.showMoreSearch
? 'el-icon-arrow-up'
: 'el-icon-arrow-down'
"
/>
</a>
</el-col>
</el-row>
</el-form>
<!-- 查询表单结束 -->
<!-- 批量操作 -->
<slot name="buttonLeftOnTable" />
<el-button
v-if="
option.buttons.add.isShow == undefined
? true
: option.buttons.add.isShow
"
v-permission="option.buttons.add.permission"
type="primary"
icon="el-icon-plus"
@click="handleOpenEditView('add')"
>新增</el-button
>
<el-button
v-if="
option.buttons.delete.isShow == undefined
? true
: option.buttons.delete.isShow
"
v-permission="option.buttons.delete.permission"
:disabled="disableBatchDelete"
type="danger"
icon="el-icon-delete"
@click="handleDeleteBatch()"
>删除</el-button
>
<!-- 表格开始 -->
<el-table
class="anji_curd_table"
:data="records"
border
@selection-change="handleSelectionChange"
@sort-change="handleSortChange"
>
<!--多选-->
<el-table-column fixed type="selection" width="50" align="center" />
<!--隐藏列-->
<el-table-column v-if="tableExpandColumns.length > 0" type="expand">
<template slot-scope="scope">
<p
v-for="item in tableExpandColumns"
:key="item.field"
class="table-expand-item"
>
<span class="titel"> {{ item.label }}: </span>
<span>{{ scope.row[item.field] }}</span>
</p>
</template>
</el-table-column>
<!--序号-->
<el-table-column label="序号" min-width="50" align="center">
<template slot-scope="scope">
{{
queryParams.pageSize * (queryParams.pageNumber - 1) +
scope.$index +
1
}}
</template>
</el-table-column>
<template v-for="item in option.columns">
<el-table-column
v-if="item.tableHide != true && item.columnType != 'expand'"
:key="item.field"
:prop="item.field"
:label="fieldLabel(item)"
:min-width="item.minWidth || 110"
:sortable="item.sortable"
:show-overflow-tooltip="true"
align="center"
>
<template slot-scope="scope">
<div v-if="item.columnType == 'imgPreview'">
<!-- 图片缩略图-->
<el-image
style="width: 25%; height: 50%"
fit="contain"
:src="scope.row[item.field]"
:preview-src-list="[scope.row[item.field]]"
/>
</div>
<div v-else>
<span v-if="item.inputType == 'switch' && !item.colorStyle">
<el-switch
v-model.trim="scope.row[item.field]"
:active-value="1"
:inactive-value="0"
active-color="#5887fb"
inactive-color="#ccc"
@change="switchChange(scope.row, item.switchOption)"
/>
</span>
<!-- 带单位 -->
<span v-else-if="item.inputType == 'anji-input'">{{
fieldValueByAnjiInput(scope.row[item.field], item)
}}</span>
<!--表格 a 合并 b上-->
<span v-else-if="item.mergeColumn"
>{{ scope.row[item.field] }}({{
scope.row[item.mergeColumn]
}})</span
>
<!-- 没有单位 -->
<span
v-else-if="item.colorStyle"
:class="item.colorStyle[scope.row[item.editField]]"
>{{ fieldValueByRowRenderer(scope.row, item) }}</span
>
<span v-else>{{
fieldValueByRowRenderer(scope.row, item)
}}</span>
<!-- 正常展示模式
<div v-if="!item.custom">
是第一列数据 && 需要高亮字段不为false 高亮并且可以点击
<span v-if="!index && item.operate !== false" class="view" @click="handleOpenEditView('view', scope.row)">{{ scope.row[item.field] }}</span>
<span v-else>{{ scope.row[item.field] }}</span>
</div>
-->
<!-- 自定义展示数据
<div v-else v-html="item.renderer(scope.row)" />-->
</div>
</template>
</el-table-column>
</template>
<!--操作栏-->
<el-table-column
align="center"
fixed="right"
label="操作"
:width="
option.buttons.customButton &&
option.buttons.customButton.operationWidth
? option.buttons.customButton.operationWidth
: 100
"
>
<template slot-scope="scope">
<slot name="edit" :msg="scope.row" />
<el-button
v-if="
(option.buttons.query.isShow == undefined
? true
: option.buttons.query.isShow) &&
hasPermission(option.buttons.edit.permission) == false
"
type="text"
size="small"
@click="handleOpenEditView('view', scope.row)"
v-permission="option.buttons.query.permission"
>查看</el-button
>
<el-button
v-if="
option.buttons.edit.isShow == undefined
? true
: option.buttons.edit.isShow
"
type="text"
size="small"
@click="handleOpenEditView('edit', scope.row)"
v-permission="option.buttons.edit.permission"
>编辑</el-button
>
<el-button
v-if="
hasRowCustomButton == false &&
option.buttons.delete.isShow == undefined
? true
: option.buttons.edit.isShow
"
type="text"
size="small"
@click="handleDeleteBatch(scope.row)"
v-permission="option.buttons.delete.permission"
>删除</el-button
>
<el-dropdown v-if="hasRowCustomButton" trigger="click">
<span class="el-dropdown-link">
更多<i class="el-icon-caret-bottom el-icon--right" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item class="clearfix">
<slot name="rowButton" :msg="scope.row" />
<el-button
v-if="
option.buttons.delete.isShow == undefined
? true
: option.buttons.edit.isShow
"
type="text"
size="small"
@click="handleDeleteBatch(scope.row)"
v-permission="option.buttons.delete.permission"
>删除</el-button
>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<div class="pagination">
<el-pagination
v-show="total > 0"
background
:current-page.sync="queryParams.pageNumber"
:page-sizes="$pageSizeAll"
:page-size="queryParams.pageSize"
layout="total, prev, pager, next, jumper, sizes"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
<div>
<slot name="tableSelectionBtn" :selection="checkRecords" />
</div>
</div>
<!-- 表格结束 -->
<EditDialog
ref="edit"
:option="option"
:model-type="editDialogModelType"
:visible="editDialogOpen"
:row-data="editDialogRowData"
@closeEvent="editDialogClosedEvent"
>
<template v-slot:customCard>
<slot name="cardInEditPage" />
</template>
<template slot="editBtn" slot-scope="scope">
<slot name="editBtnPage" :rowData="scope" />
</template>
</EditDialog>
</div>
<slot name="pageSection" />
</div>
</template>
<script>
import AnjiTree from "@/components/AnjiPlus/anji-tree.vue";
import EditDialog from "./edit";
import request from "@/utils/request";
export default {
components: {
EditDialog,
AnjiTree
},
props: {
option: {
require: true,
type: Object,
default: () => {
return {
//
queryFormFields: [],
//
buttons: {
query: {},
edit: {},
delete: {},
add: {}
},
//
columns: [],
queryFormChange: (fileName, val) => {}
};
}
}
},
data() {
return {
//
queryParams: {
showMoreSearch: false, //
pageNumber: 1,
pageSize: 10,
order: "",
sort: ""
},
checkRecords: [], //
records: [], //
total: 0, //
//
editDialogOpen: false, //
editDialogRowData: {}, //
editDialogModelType: "view", //
hasRowCustomButton: false //
};
},
computed: {
//
queryFormTreeField() {
var treeField = this.option.queryFormFields.find(
item => item["inputType"] == "anji-tree"
);
return treeField;
},
//
hasTreeFieldInQueryForm() {
return this.isNotBlank(this.queryFormTreeField);
},
//
queryFormFieldExcludeTree() {
var treeFields = this.option.queryFormFields.filter(
item => item["inputType"] != "anji-tree"
);
return treeFields;
},
//
primaryKeyFieldName() {
var primaryKey = this.option.columns.find(
item => item["primaryKey"] == true
);
if (primaryKey != null) {
return primaryKey["field"];
} else {
return null;
console.warn(
"在columns中查找primaryKey=true失败会导致查询详情和删除失败"
);
}
},
//
tableExpandColumns() {
var expandColumns = this.option.columns.filter(
item => item["columnType"] == "expand"
);
return expandColumns;
},
//
disableBatchDelete() {
return this.checkRecords.length <= 0;
}
},
created() {
// input
this.option.queryFormFields.forEach(item => {
//
this.$set(this.queryParams, item.field, item.defaultValue || null);
});
//
this.handleQueryForm("query");
this.queryFormChange();
},
mounted() {
if (this.$scopedSlots["rowButton"] != null) {
this.hasRowCustomButton = true;
} else {
this.hasRowCustomButton = false;
}
},
methods: {
queryFormFieldSpan(item) {
// console.log(item)
if (item.span != null) {
return item.span;
} else {
return 6;
}
// let rowLength = this.option.queryFormFields.length;
// console.log(rowLength, "ss")
// console.log(rowLength % 3)
// if (rowLength <= 3) {
// return 6
// }
// else if (rowLength % 3 == 0) {
// return 8
// } else if (rowLength > 6) {
// return 8
// }
},
//
handleToggleMoreSearch() {
this.queryParams.showMoreSearch = !this.queryParams.showMoreSearch;
},
//
handleSortChange(column) {
// {column: {}, prop: "orgCode", order: "ascending"}
if (column == null || column.prop == null) {
console.warn("排序字段名prop为空无法排序");
return;
}
var sort = column.prop; //
var order = column.order == "ascending" ? "ASC" : "DESC";
this.queryParams["sort"] = sort;
this.queryParams["order"] = order;
this.handleQueryForm("query");
},
//
handleQueryForm(from) {
//
if (from == "query") {
if (this.hasTreeFieldInQueryForm) {
delete this.queryParams[this.queryFormTreeField.field];
}
}
//
if (from == "tree") {
if (this.hasTreeFieldInQueryForm) {
var treeVal = this.queryParams[this.queryFormTreeField.field];
this.queryParams = {
pageNumber: 1,
pageSize: 10
};
this.queryParams[this.queryFormTreeField.field] = treeVal;
}
}
//
if (
this.isBlank(this.queryParams["order"]) &&
this.isNotBlank(this.option.buttons.query.order)
) {
this.queryParams["sort"] = this.option.buttons.query.sort;
this.queryParams["order"] = this.option.buttons.query.order;
}
this.queryParams.pageNumber = 1;
this.handleQueryPageList();
},
//
async handleQueryPageList() {
var params = this.queryParams;
// urlcode var params = this.urlEncodeObject(this.queryParams, 'order,sort')
const { data, code } = await this.option.buttons.query.api(params);
if (code != "200") return;
this.records = data.records;
this.total = data.total;
},
//
handleResetForm() {
this.queryParams = {
pageNumber: 1,
pageSize: 10
};
// this.$refs['queryForm'].resetFields()
// this.records = []
// this.total = 0
},
//
handleTreeNodeCheck() {
this.handleQueryForm("tree");
//
var treeFieldName = this.queryFormTreeField["field"];
for (var i = 0; i < this.option.columns.length; i++) {
var item = this.option.columns[i];
if (
item["editField"] == treeFieldName ||
item["field"] == treeFieldName
) {
this.$set(
this.option.columns[i],
"defaultValue",
this.queryParams[treeFieldName]
);
break;
}
}
},
//
handleOpenEditView(modelType, row) {
if (modelType == "view" || modelType == "edit") {
this.editDialogRowData = row;
}
this.editDialogModelType = modelType;
if (modelType == "add") {
//
this.editDialogOpen = true;
}
const obj = {
type: modelType,
value: row
};
this.$emit("handleCustomValue", obj);
},
//
editDialogClosedEvent(value) {
//
this.editDialogOpen = false;
//
if (
this.hasTreeFieldInQueryForm &&
this.$refs.queryFormTree != null &&
!value
) {
this.$refs.queryFormTree.queryData();
}
this.handleQueryPageList();
//
this.$refs.edit.$refs.mainForm.$refs.editForm.resetFields();
},
//
handleDeleteBatch(row) {
var ids = [];
if (row != null) {
ids.push(row[this.primaryKeyFieldName]); //
} else {
//
ids = this.checkRecords.map(item => item[this.primaryKeyFieldName]);
}
this.$confirm("删除确认", "确认要删除吗?", {
type: "warning",
confirmButtonClass: "delete_sure",
cancelButtonClass: "el-button--danger is-plain"
})
.then(() => {
this.option.buttons.delete.api(ids).then(res => {
// {code: "200", message: "", data: true}
this.checkRecords = [];
//
if (
this.hasTreeFieldInQueryForm &&
this.$refs.queryFormTree != null
) {
this.$refs.queryFormTree.queryData();
}
this.handleQueryPageList();
});
})
.catch(e => {
e;
});
},
//
handleSelectionChange(val) {
this.checkRecords = val;
},
//
handleCurrentChange(pageNumber) {
this.queryParams.pageNumber = pageNumber;
this.handleQueryPageList();
},
// size
handleSizeChange(val) {
this.queryParams.pageNumber = 1;
this.queryParams.pageSize = val;
this.handleQueryPageList();
},
// table
thumbnailUrl(row, field) {
// return 'http://10.108.3.123:9090/tms/file/download/79ee7e8b-2a9a-4142-b06d-706ac8089205'
// if (row.filePath) {
// if (row.filePath.endsWith('xlsx') || row.filePath.endsWith('xls')) {
// return fileExcel;
// } else if (row.filePath.endsWith('pdf')) {
// return filePdf;
// }
// return process.env.VUE_APP_BASE_API + '/tms/file/download/' + row.fileId;
// } else {
// return logo;
// }
},
//
fieldLabel(columnConfig) {
if (columnConfig == null) {
return "";
}
if (
columnConfig.inputType == "anji-input" &&
columnConfig.anjiInput != null
) {
return `${columnConfig.label}(${columnConfig.anjiInput.unit})`;
} else {
return columnConfig.label;
}
},
//
fieldValueByAnjiInput(value, columnConfig) {
if (columnConfig == null) {
return value;
}
if (
columnConfig.inputType == "anji-input" &&
columnConfig.anjiInput != null
) {
return value / columnConfig.anjiInput.conversion;
} else {
return value;
}
},
//
fieldValueByRowRenderer(row, columnConfig) {
if (
columnConfig == null ||
typeof columnConfig.fieldTableRowRenderer != "function"
) {
return row[columnConfig.field];
} else {
return columnConfig.fieldTableRowRenderer(row);
}
},
// crudsaveForm
getMainEntity() {
return this.$refs.edit.getSaveForm();
},
setMainEntity(object) {
this.$refs.edit.setSaveForm(object);
},
async switchChange(val, api) {
request({
url: api.url,
method: "put",
headers: { noPrompt: false },
data: [val.id]
}).then(response => {
this.handleQueryPageList();
});
},
queryFormChange(fileName, fieldVal) {
if (typeof this.option.queryFormChange == "function") {
this.option.queryFormChange(this.queryParams, fileName, fieldVal);
}
}
}
};
</script>
<style scoped lang="scss">
.style-btn {
pointer-events: none;
}
.page-container {
height: 100%;
position: relative;
.left-container {
width: 20%;
position: absolute;
top: 0;
left: 0;
background: #fff;
border-radius: 4px 0px 0px 4px;
padding: 20px 20px 0;
overflow: hidden;
overflow-y: auto;
height: 100%;
}
.right-container {
width: calc(80% - 5px);
position: absolute;
top: 0;
right: 0;
background: #fff;
border-radius: 0px 4px 4px 0px;
padding: 20px 20px 0;
height: 100%;
}
}
.el-table .cell,
.el-table td div {
overflow: hidden;
text-overflow: ellipsis;
}
.el-dropdown {
font-size: 12px;
display: inline;
color: #5887fb;
cursor: pointer;
}
.el-dropdown-menu--mini .el-dropdown-menu__item {
min-width: 80px;
max-width: 110px;
float: right;
.el-button--text {
float: right;
}
&:hover {
background: none !important;
}
.el-button--mini {
float: right;
}
.el-button + .el-button {
margin-left: 0 !important;
float: right;
}
}
.pagination {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 20px;
}
.anji_curd_table {
margin-top: 20px;
}
</style>

@ -1,362 +0,0 @@
<!--
* @Author: lide1202@hotmail.com
* @Date: 2021-5-4 11:04:24
* @Last Modified by: lide1202@hotmail.com
* @Last Modified time: 2021-5-6 11:04:24
!-->
<template>
<div v-if="option['hide'] == null || option['hide'] == false" class="anji-card">
<div class="card-head">
{{ option.title }}
<div class="main-card-header-button">
<el-button type="text" @click="handleSetRowColNum(4)">||||</el-button>
<el-button type="text" @click="handleSetRowColNum(3)">|||</el-button>
<el-button type="text" @click="handleSetRowColNum(2)">||</el-button>
</div>
</div>
<div class="card-body">
<el-form ref="editForm" :model="editForm" :label-width="option.labelWidth || '100px'">
<!--:disabled="modelType == 'view'"-->
<template v-for="group in columnGroups">
<el-divider v-if="groupModel" :key="group" content-position="left">{{ group }}</el-divider>
<el-row :key="group" class="form_table">
<template v-for="item in groupFormFields[group]">
<el-col v-if="fieldIsHide(item.editHide) == false" :key="item.editField" :span="item.rowColSpan == null ? cardRowColSpan : item.rowColSpan">
<el-form-item :label="item.label" :rules="item.rules" :prop="item.editField" :disabled="item.disabled">
<!-- 输入框 -->
<span v-if="item.tips != '' && item.tips != null" :style="{ 'margin-left': '-13px' }" class="input_tips">
<el-tooltip class="item" effect="dark" :content="item.tips" placement="top-start">
<svg-icon icon-class="tishi-yiwen" />
</el-tooltip>
</span>
<el-input v-if="item.inputType == 'input'" v-model.trim="editForm[item.editField]" :placeholder="item.placeholder || '请输入'" :clearable="item.clearable !== false" :disabled="fieldIsDisable(item.disabled)" @change="(value) => formChange(item.editField, value, null)" />
<!-- 开关 -->
<el-switch v-else-if="item.inputType == 'switch'" v-model.trim="editForm[item.editField]" :disabled="fieldIsDisable(item.disabled)" :active-value="1" :inactive-value="0" inactive-color="#ccc" active-color="#5887fb" @change="(value) => formChange(item.editField, value, null)" />
<el-input-number v-else-if="item.inputType == 'input-number'" v-model.trim="editForm[item.editField]" :min="item.inputNumberOption.min" :max="item.inputNumberOption.max" :placeholder="item.placeholder || '请输入'" :clearable="item.clearable !== false" :disabled="fieldIsDisable(item.disabled)" @change="(value) => formChange(item.editField, value, null)" />
<!-- 自定义input -->
<anji-input v-else-if="item.inputType == 'anji-input'" v-model.trim="editForm[item.editField]" :unit="item.anjiInput.unit" :conversion="item.anjiInput.conversion" :keep-point="item.anjiInput.keepPoint" :rounding="item.anjiInput.rounding" :placeholder="item.placeholder || '请输入'" :clearable="item.clearable !== false" :disabled="fieldIsDisable(item.disabled)" @change="(value) => formChange(item.editField, value, null)" />
<!-- 下拉框 -->
<anji-select
v-else-if="item.inputType == 'anji-select'"
v-model.trim="editForm[item.editField]"
:multiple="item.anjiSelectOption.multiple"
:disabled="fieldIsDisable(item.disabled)"
:dict-code="item.anjiSelectOption.dictCode"
:placeholder="item.placeholder"
:url="item.anjiSelectOption.url"
:method="item.anjiSelectOption.method"
:query-param="item.anjiSelectOption.queryParam"
:merge-label="item.anjiSelectOption.mergeLabel"
:option="item.anjiSelectOption.option"
:label="item.anjiSelectOption.label"
:remote-filter="item.anjiSelectOption.remoteFilter"
:disabled-options="item.anjiSelectOption.disabledOptions"
@change="(value, option) => formChange(item.editField, value, option)"
/>
<!-- 日期时间框 -->
<el-date-picker v-else-if="item.inputType.indexOf('date') >= 0" v-model="editForm[item.editField]" style="width: 100%" :placeholder="item.placeholder || '请选择'" :type="item.inputType" :format="item.format" :value-format="item.valueFormat" :disabled="fieldIsDisable(item.disabled)" :clearable="item.clearable !== false" @change="(value) => formChange(item.editField, value, null)" />
<!-- checkbox -->
<anji-checkbox v-else-if="item.inputType == 'checkbox'" v-model.trim="editForm[item.editField]" :dict-code="item.anjiCheckbox.dictCode" :label="item.anjiCheckbox.label" :disabled="fieldIsDisable(item.disabled)" @change="(value, options) => formChange(item.editField, value, options)" />
<!-- 城市三级联动 -->
<anji-cascader v-else-if="item.inputType == 'anji-cascader'" v-model.trim="editForm[item.editField]" :disabled="fieldIsDisable(item.disabled)" :url="item.anjiCascader.url" @change="(value) => formChange(item.editField, value, null)" />
<!-- 上传组件 -->
<anji-upload v-else-if="item.inputType == 'anji-upload'" v-model.trim="editForm[item.editField]" :up-load-url="item.anjiUpload.upLoadUrl" :view-url="item.anjiUpload.viewUrl" :upload-type="item.anjiUpload.uploadType" :limit="item.anjiUpload.limit" @change="(value) => formChange(item.editField, value, null)" />
<!-- input自带输入建议 -->
<anji-autocomplete v-else-if="item.inputType == 'anji-autocomplete'" v-model.trim="editForm[item.editField]" :disabled="fieldIsDisable(item.disabled)" :label="item.anjiAutocomplete.label" :option="item.anjiAutocomplete.option" :appoint-value="item.anjiAutocomplete.appointValue" :url="item.anjiAutocomplete.url" @change="(value, option) => formChange(item.editField, value, option)" />
<!-- textarea -->
<el-input v-else-if="item.inputType == 'textarea'" v-model.trim="editForm[item.editField]" :placeholder="item.placeholder || '请输入'" :clearable="item.clearable !== false" :disabled="fieldIsDisable(item.disabled)" type="textarea" :rows="2" @change="(value) => formChange(item.editField, value, null)" />
<el-input v-else placeholder="组件不支持此类型表单请至组件内部自行扩展" disabled />
</el-form-item>
</el-col>
</template>
</el-row>
</template>
</el-form>
</div>
</div>
</template>
<script>
export default {
components: {},
props: {
modelType: String, // add view edit
showDialog: Boolean,
option: {
// json
type: [Object],
default: () => {
return {
title: '', //
labelWidth: '', // label
queryFormFields: [], //
buttons: {
//
query: {},
edit: {},
delete: {},
add: {},
},
columns: [], //
formChange: (formData, fieldName, fieldVal, fieldExtend) => {}, //
}
},
},
// relateDatarelateData
relateData: {
type: [Object],
default: () => {
return {}
},
},
value: {
type: [Object],
default: () => {
return {}
},
},
},
data() {
return {
cardRowColNum: 2, //
editForm: {}, //
}
},
computed: {
//
primaryKeyFieldName() {
var primaryKey = this.option.columns.find((item) => item['primaryKey'] == true)
if (primaryKey != null) {
return primaryKey['field']
} else {
return null
console.warn('在columns中查找primaryKey=true失败会导致查询详情和删除失败')
}
},
//
joinColumn() {
var columnName = this.option.joinColumn
if (this.isBlank(columnName)) {
console.warn('在joinEntity中查找joinColumn属性失败会导致查询详情和删除失败')
columnName = ''
}
return columnName
},
// keyfield editField
formFields() {
if (this.option.columns == null) {
return []
}
var fields = this.deepClone(this.option.columns)
fields = fields.map((item) => {
if (this.isBlank(item['editField'])) {
item['editField'] = item['field']
}
//
if (this.isBlank(item['group'])) {
item['group'] = '其它'
}
return item
})
return fields
},
// col
cardRowColSpan() {
return 24 / this.cardRowColNum
},
//
columnGroups() {
if (this.isBlank(this.formFields)) {
return []
} else {
// hide != true
var groups = this.formFields
.map((item) => {
return item['group']
})
.filter((currentValue, index, arr) => {
return arr.indexOf(currentValue) == index
})
return groups
}
},
/* {
'分组1': [{column1.1}],
'分组2': [{column2.1}],
}*/
groupFormFields() {
if (this.showDialog) {
//
var groupFormFields = {}
this.columnGroups.forEach((value, index, array) => {
groupFormFields[value] = []
})
//
this.formFields.forEach((item, index, array) => {
groupFormFields[item['group']].push(item)
})
return groupFormFields
}
return []
},
groupModel() {
return this.columnGroups.length > 1
},
},
created() {
// v-modelvaluethis.editForm
this.$watch(
function () {
return this.value
},
function (newVal, oldVal) {
this.editForm = newVal
// v-modelform
this.formChange()
}
)
// relateDatagoodsgoodsCode
this.$watch(
function () {
return this.relateData[this.joinColumn]
},
function (newVal, oldVal) {
// ()this.relateData = {}
if (this.isBlank(this.relateData)) {
this.cardRowColNum = 2
this.editForm = {}
return
}
//
if (this.isNotBlank(newVal)) {
this.queryDetail()
}
}
)
},
mounted() {
// v-model
if (this.isNotBlank(this.value)) {
this.editForm = this.value
this.formChange()
}
//
if (this.isNotBlank(this.relateData) && this.isNotBlank(this.relateData[this.joinColumn])) {
this.queryDetail()
}
},
methods: {
// true/false/ 'hideOnAdd hideOnView hideOnEdit'
fieldIsHide(editHide) {
if (typeof editHide == 'boolean') {
return editHide
}
if (typeof editHide == 'string') {
if (this.modelType == 'add') {
return editHide.indexOf('hideOnAdd') >= 0
}
if (this.modelType == 'view') {
return editHide.indexOf('hideOnView') >= 0
}
if (this.modelType == 'edit') {
return editHide.indexOf('hideOnEdit') >= 0
}
}
return false
},
// true/false/ 'disableOnAdd disableOnView disableOnEdit'
fieldIsDisable(disable) {
if (typeof disable == 'boolean') {
return disable
}
if (typeof disable == 'string') {
if (this.modelType == 'add') {
return disable.indexOf('disableOnAdd') >= 0
}
if (this.modelType == 'view') {
return disable.indexOf('disableOnView') >= 0
}
if (this.modelType == 'edit') {
return disable.indexOf('disableOnEdit') >= 0
}
}
return false
},
//
handleSetRowColNum(num) {
this.cardRowColNum = num
this.$emit('changeRowColNum', num)
},
async queryDetail() {
var queryParams = this.relateData
const { data, code } = await this.option.buttons.queryByPrimarykey.api(queryParams)
if (code != '200') return
this.editForm = data
this.formChange()
},
//
validate(callback) {
this.$refs.editForm.validate(async (valid, obj) => {
if (callback != null) {
callback(valid)
}
})
},
handleSave(callback) {
this.$refs.editForm.validate(async (valid, obj) => {
if (valid) {
if (this.modelType == 'add') {
// edit-from
if (typeof this.option.beforeInsert == 'function') {
this.option.beforeInsert(this.relateData, this.editForm)
}
const { code, message } = await this.option.buttons.add.api(this.editForm)
if (code == '200') {
if (callback != null) {
callback()
}
} else {
console.log(`提交表单调用新增接口失败:${message}`)
}
} else {
// edit-from
if (typeof this.option.beforeUpdate == 'function') {
this.option.beforeUpdate(this.relateData, this.editForm)
}
const { code, message } = await this.option.buttons.edit.api(this.editForm)
if (code == '200') {
if (callback != null) {
callback()
}
} else {
console.log(`提交表单调用更新接口失败:${message}`)
}
}
} else {
console.log('表单校验失败')
}
})
},
// v-model
formChange(fieldName, fieldVal, fieldExtend) {
this.$emit('input', this.editForm)
// optionformChange
if (typeof this.option.formChange == 'function') {
this.option.formChange(this.editForm, fieldName, fieldVal, fieldExtend)
}
},
},
}
</script>
<style scoped lang="scss">
.input_tips {
position: absolute;
margin-top: -8px;
.svg-icon {
font-size: 20px;
color: rgb(71, 8, 8);
}
}
</style>

@ -1,498 +0,0 @@
<!--
* @Author: lide1202@hotmail.com
* @Date: 2021-5-4 11:04:24
* @Last Modified by: lide1202@hotmail.com
* @Last Modified time: 2021-5-6 11:04:24
!-->
<template>
<div v-if="option['hide'] == null || option['hide'] == false"
class="anji-card">
<div class="card-head">{{ option.title }}</div>
<div class="card-body">
<el-form ref="form"
:model="form">
<!-- 表格开始 -->
<el-table :data="formRecordsUndelete"
border
:row-class-name="tableRowClassAdapter"
@selection-change="handleSelectionChange"
@row-click="handleTableRowClick">
<!-- <el-table-column fixed type="selection" width="50" align="center" /> -->
<el-table-column label="序号"
min-width="50"
align="center">
<template slot-scope="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
<template v-for="item in option.columns">
<el-table-column v-if="fieldIsHide(item.tableHide) != true && item.columnType != 'expand'"
:key="item.field"
:label="item.label"
:min-width="item.minWidth || 110"
align="center">
<template slot-scope="scope">
<el-form-item :prop="'records.' + scope.$index + '.' + item.field"
:rules="item.rules">
<!-- 输入框 -->
<el-input v-if="item.inputType == 'input'"
v-model="scope.row[item.field]"
size="small"
:placeholder="item.placeholder || '请输入'"
:clearable="item.clearable !== false"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
@change="(value) => tableRowChange(scope.$index, item.field, value)" />
<!-- 开关 -->
<el-switch v-else-if="item.inputType == 'switch'"
v-model="scope.row[item.field]"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
:active-value="item.switchOption.disableValue"
:inactive-value="item.switchOption.enableValue"
@change="(value) => tableRowChange(scope.$index, item.field, value)"
active-color="#5887fb"
inactive-color="#ccc">
</el-switch>
<el-input v-else-if="item.inputType == 'input-number'"
v-model="scope.row[item.field]"
size="small"
:min="item.inputNumberOption.min"
:max="item.inputNumberOption.max"
:placeholder="item.placeholder || '请输入'"
:clearable="item.clearable !== false"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
@change="(value) => tableRowChange(scope.$index, item.field, value)" />
<!-- 自定义input -->
<anji-input v-else-if="item.inputType == 'anji-input'"
v-model.trim="scope.row[item.field]"
:default-value="item.defaultValue"
:unit="item.anjiInput.unit"
:conversion="item.anjiInput.conversion"
:placeholder="item.placeholder || '请输入'"
:clearable="item.clearable !== false"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
@change="(value) => tableRowChange(scope.$index, item.field, value)" />
<!-- 下拉框 -->
<anji-select v-else-if="item.inputType == 'anji-select'"
v-model.trim="scope.row[item.field]"
:multiple="item.anjiSelectOption.multiple"
:default-value="item.defaultValue"
:dict-code="item.anjiSelectOption.dictCode"
:url="item.anjiSelectOption.url"
:method="item.anjiSelectOption.method"
:query-param="item.anjiSelectOption.queryParam"
:option="item.anjiSelectOption.option"
:label="item.anjiSelectOption.label"
:disabled-options="item.anjiSelectOption.disabledOptions"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
@change="(value, option) => tableRowChange(scope.$index, item.field, value, option)" />
<!-- 日期时间框 -->
<el-date-picker v-else-if="item.inputType.indexOf('date') >= 0"
v-model="scope.row[item.field]"
style="width: 100%"
:placeholder="item.placeholder || '请选择'"
:type="item.inputType"
:clearable="item.clearable !== false"
:disabled="saveButtonStatus[scope.$index] == 'inShow' || item.disabled"
@change="(value) => tableRowChange(scope.$index, item.field, value)" />
<!-- 待扩展的表单类型请自行扩展 -->
<el-input v-else
placeholder="组件不支持此类型表单请至组件内部自行扩展"
disabled />
</el-form-item>
</template>
</el-table-column>
</template>
<el-table-column fixed="right"
label="操作"
width="100">
<template slot-scope="scope">
<el-button type="text"
size="small"
@click="handleAddOrUpdate(scope.row, scope.$index)">{{ getRowEditButton(scope.$index) }}</el-button>
<el-button type="text"
size="small"
@click="handleDelete(scope.row, scope.$index)">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 表格结束 -->
</el-form>
<button v-if="modelType != 'view'"
class="table-add-row-button"
@click="handleAdd">
<i class="el-icon-plus" />
<span>新增</span>
</button>
</div>
</div>
</template>
<script>
const ROW_DELETE_FLAG = 'deletedFlag'
export default {
components: {},
props: {
modelType: String, // add view edit
option: {
// json
type: [Object],
default: () => {
return {
title: '', //
labelWidth: '',
queryFormFields: [], //
buttons: {
//
query: {},
edit: {},
delete: {},
add: {},
},
columns: [], //
}
},
},
relateData: {
//
type: [Object],
default: () => {
return {}
},
},
value: {
type: [Array],
default: () => {
return []
},
},
valueNew: {
type: [Array],
default: () => {
return []
},
}
},
data () {
return {
checkRecords: [], //
form: {
records: [], //
total: 0, //
},
saveButtonStatus: [], // inShow inEditing inAdding
rowIdList: []
}
},
computed: {
//
primaryKeyFieldName () {
var primaryKey = this.option.columns.find((item) => item['primaryKey'] == true)
if (primaryKey != null) {
return primaryKey['field']
} else {
return null
console.warn('在columns中查找primaryKey=true失败会导致查询详情和删除失败')
}
},
//
joinColumn () {
var columnName = this.option.joinColumn
if (this.isBlank(columnName)) {
console.warn('在columns中查找关联字段失败会导致查询详情和删除失败孙子关联表忽略该错误')
columnName = ''
}
return columnName
},
//
formRecordsUndelete () {
if (this.form.records == null) {
return []
}
return this.form.records.filter((item) => item[ROW_DELETE_FLAG] == null || item[ROW_DELETE_FLAG] == false)
},
},
watch: {},
created () {
// relateData joinColumn
if (this.isNotBlank(this.joinColumn)) {
this.$watch(
function () {
return this.relateData[this.joinColumn]
},
function (newVal, oldVal) {
//
if (this.isNotBlank(newVal)) {
this.handleQueryPageList(newVal)
} else {
// ()this.relateData = {}
this.checkRecords = []
this.form.records = []
this.form.total = 0
this.saveButtonStatus = []
}
}
)
}
},
mounted () {
//
if (this.isNotBlank(this.relateData) && this.isNotBlank(this.relateData[this.joinColumn])) {
this.handleQueryPageList()
}
},
methods: {
// true/false/ 'hideOnAdd hideOnView hideOnEdit'
fieldIsHide (tableHide) {
if (typeof tableHide == 'boolean') {
return tableHide
}
if (typeof tableHide == 'string') {
if (this.modelType == 'add') {
return tableHide.indexOf('hideOnAdd') >= 0
}
if (this.modelType == 'view') {
return tableHide.indexOf('hideOnView') >= 0
}
if (this.modelType == 'edit') {
return tableHide.indexOf('hideOnEdit') >= 0
}
}
return false
},
//
getRowEditButton (index) {
if (this.saveButtonStatus[index] == 'inEditing') {
return 'btn_savetemp'
} else if (this.saveButtonStatus[index] == 'inAdding') {
return 'btn_savetemp'
} else if (this.saveButtonStatus[index] == 'inShow') {
return 'btn_edit'
} else {
return 'not_permission'
}
},
//
tableRowClassAdapter ({ row, rowIndex }) {
row.index = rowIndex
},
//
async handleQueryPageList (joinColumnValue) {
if (this.isBlank(joinColumnValue)) {
joinColumnValue = this.relateData[this.joinColumn]
}
var params = {}
params[this.joinColumn] = joinColumnValue
this.queryPageList(params)
},
//
async queryPageList (params) {
//
if (this.isNotBlank(this.option.buttons.query.order)) {
params['sort'] = this.option.buttons.query.sort
params['order'] = this.option.buttons.query.order
}
const { data, code } = await this.option.buttons.query.api(params)
if (code != '200') return
this.form.records = data.records
this.form.total = data.total
this.$emit('input', this.form.records)
for (var i = 0; i < this.form.total; i++) {
this.saveButtonStatus.push('inShow')
}
},
//
handleSelectionChange (val) {
this.checkRecords = val
},
//
handleTableRowClick (row, column, event) {
// console.log(row)
// console.log(column)
// optiontableRowClick
if (typeof this.option.tableRowClick == 'function') {
this.option.tableRowClick(this.form.records, row, row.index, this.relateData)
}
},
//
tableRowChange (rowIndex, fieldName, fieldVal, fieldExtend) {
//
this.$emit('input', this.form.records)
// optiontableRowChange
if (typeof this.option.tableChange == 'function') {
this.option.tableChange(this.form.records, rowIndex, fieldName, fieldVal, fieldExtend, this.relateData)
}
},
//
handleAdd () {
this.saveButtonStatus.push('inAdding')
this.form.records.push({})
},
// Change,
handleUpdata () {
this.saveButtonStatus = []
this.form.records = []
},
//
handleAddOrUpdate (row, index) {
//
if (this.saveButtonStatus[index] == 'inEditing' || this.saveButtonStatus[index] == 'inAdding') {
this.handleSaveTemp(row, index)
} else {
this.$set(this.saveButtonStatus, index, 'inEditing')
}
},
//
validate (callback) {
this.$refs['form'].validate(async (valid, obj) => {
if (callback != null) {
callback(valid)
}
})
},
//
async handleSaveTemp (row, index) {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.isBlank(row[this.primaryKeyFieldName])) {
//
if (typeof this.option.beforeInsert == 'function') {
this.option.beforeInsert(this.relateData, row)
}
} else {
//
if (typeof this.option.beforeUpdate == 'function') {
this.option.beforeUpdate(this.relateData, row)
}
}
//
this.$set(this.saveButtonStatus, index, 'inShow')
//
this.$emit('input', this.form.records)
}
})
/*
this.$refs['form'].validate((valid) => {
if (valid) {
//
if (this.isBlank(row[this.primaryKeyFieldName])) {
//
if (typeof this.option.beforeInsert == 'function') {
this.option.beforeInsert(this.relateData, row)
}
//
this.option.buttons.add.api(row).then((response) => {
if (response.code == 200) {
this.$set(this.saveButtonStatus, index, 'inShow')
//
this.handleQueryPageList()
}
})
} else {
//
if (typeof this.option.beforeUpdate == 'function') {
this.option.beforeUpdate(this.relateData, row)
}
//
this.option.buttons.edit.api(row).then((response) => {
if (response.code == 200) {
this.$set(this.saveButtonStatus, index, 'inShow')
//
this.handleQueryPageList()
}
})
}
} else {
console.log('valid fail')
return false
}
})
*/
},
//
handleDelete (row, index) {
this.saveButtonStatus.splice(index, 1) //
//
if (this.saveButtonStatus[index] == 'inAdding') {
this.form.records.splice(index, 1)
this.saveButtonStatus.splice(index, 1)
this.$emit('input', this.form.records)
return
}
// if (this.isBlank(row) || this.isBlank(row[this.primaryKeyFieldName])) {
// return
// }
//
// index
// var realIndex = this.form.records.findIndex((item) => item[this.primaryKeyFieldName] == row[this.primaryKeyFieldName])
// row[ROW_DELETE_FLAG] = true
// this.$set(this.form.records, realIndex, row)
// this.$emit('input', this.form.records)
this.form.records.splice(index, 1)
this.rowIdList.push(row.id)
this.$emit('input', this.form.records)
this.$emit('update:valueNew', this.rowIdList)
/*
之前是直接调用接口删除后面统一改成在主表接口中增加更新删除
//
var primaryKey = row[this.primaryKeyFieldName]
this.$confirm(this.$lang('promptMessage_deleteTip'), this.$lang('promptMessage_deleteTipTitle'), {
type: 'warning',
confirmButtonClass: 'delete_sure',
cancelButtonClass: 'el-button--danger is-plain',
})
.then(() => {
this.option.buttons.delete.api(primaryKey).then((res) => {
// {code: "200", message: "", data: true}
this.checkRecords = []
this.handleQueryPageList()
})
})
.catch((e) => {
e
})
*/
},
},
}
</script>
<style scoped lang="scss">
.table-add-row-button {
width: 100%;
margin-top: 0px;
margin-bottom: 0px;
border-color: #d9d9d9;
border-style: dashed;
line-height: 1.499;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
border: 1px solid transparent;
box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015);
cursor: pointer;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
-ms-touch-action: manipulation;
touch-action: manipulation;
height: 32px;
padding: 0 15px;
font-size: 14px;
border-radius: 4px;
color: rgba(0, 0, 0, 0.65);
background-color: #fff;
border-color: #d9d9d9;
}
</style>

@ -1,386 +0,0 @@
<!--
* @Author: lide1202@hotmail.com
* @Date: 2021-3-13 11:04:24
* @Last Modified by: lide1202@hotmail.com
* @Last Modified time: 2021-3-13 11:04:24
!-->
<template>
<el-dialog
:width="dialogWidth"
:class="dialogFullScreen?'full-screen':'notfull-screen'"
:close-on-click-modal="false"
center
:visible.sync="showDialog"
:fullscreen="dialogFullScreen"
@close="handleCloseDialog('close')"
>
<template v-slot:title>
{{ option.title + '--' + modelType }}
<button
type="button"
aria-label="Close"
class="el-dialog__headerbtn"
style="right: 50px"
@click="dialogFullScreen = !dialogFullScreen"
>
<i class="el-dialog__close el-icon el-icon-full-screen" />
</button>
</template>
<!--主表详情信息-->
<component
:is="'EditForm'"
ref="mainForm"
v-model="saveForm"
:option="option"
:model-type="modelType"
:show-dialog="showDialog"
@changeRowColNum="handleSetRowColNum"
/>
<!--关联表相关-->
<template v-for="(item, index) in joinEntitys">
<component
:is="getComponentByJoinType(item.joinType, item)"
:ref="'joinForm' + index"
:key="index"
v-model="saveForm[item.fieldNameInMainEntityOnSave]"
:value-new.sync="saveForm[item.fieldNameInMainEntityOnId]"
:option="item"
:model-type="modelType"
:relate-data="saveForm"
/>
<!--孙子的关联表-->
<template v-for="(grandsonItem, grandsonIndex) in item.joinEntitys">
<component
:is="getComponentByJoinType(grandsonItem.joinType, grandsonItem)"
ref="grandsonForm"
:key="index + '.' + grandsonIndex"
:option="grandsonItem"
:model-type="modelType"
:relate-data="saveForm"
/>
</template>
</template>
<!--自定义的卡片插槽-->
<slot name="customCard" />
<div
slot="footer"
style="text-align: center"
>
<slot
v-if="modelType =='edit'"
name="editBtn"
:rowData="rowData"
/>
<el-button
type="danger"
plain
@click="handleCloseDialog('close')"
>关闭</el-button>
<el-button
v-if="modelType!='view'"
type="primary"
plain
@click="handleValidateAndSave"
>保存</el-button>
</div>
</el-dialog>
</template>
<script>
import EditForm from './edit-form'
import EditTable from './edit-table'
export default {
name: 'EditDialog',
components: { EditForm, EditTable },
props: {
visible: {
type: [Boolean],
default: () => {
return false
},
},
rowData: {
//
type: [Object],
default: () => {
return {}
},
},
modelType: String, // add view edit
option: {
require: true,
type: Object,
default: () => {
return {
title: '', //
labelWidth: '', // label
queryFormFields: [], //
buttons: {
//
query: {},
edit: {},
delete: {},
add: {},
},
columns: [], //
}
},
},
},
data() {
return {
showDialog: false, //
dialogFullScreen: false, //
cardRowColNum: 2, //
//
saveForm: {},
//
countForValidJoinForm: 0,
}
},
computed: {
//
dialogWidth() {
if (this.cardRowColNum == 2) {
return '60%'
}
if (this.cardRowColNum == 3) {
return '70%'
}
if (this.cardRowColNum == 4) {
return '80%'
}
return '60%'
},
//
joinEntitys() {
if (this.isBlank(this.option.joinEntitys)) {
return []
} else {
return this.option.joinEntitys
// hide != true
// var entitys = this.option.joinEntitys.filter((item) => item['hide'] == null || item['hide'] == false)
// return entitys
}
},
//
countJoinEntityOneToOne() {
var entitys = this.joinEntitys.filter((item) => item['joinType'] == 'OneToOne')
if (entitys == null) {
return 0
}
return entitys.length
},
},
watch: {
// dialog
visible(newValue, oldValue) {
this.showDialog = newValue
//
this.initDefaultSaveForm()
},
rowData(newValue, oldValue) {
if (newValue != null) {
this.queryByPrimarykey(newValue)
}
},
},
mounted() {
//
this.initDefaultSaveForm()
},
methods: {
// crudsaveForm
getSaveForm() {
return this.saveForm
},
setSaveForm(saveForm) {
this.saveForm = saveForm
},
initDefaultSaveForm() {
// saveForm
var defaultSaveForm = {}
this.option.columns.forEach((item) => {
var key = item.editField
if (this.isBlank(key)) {
key = item.field
}
var val = item.defaultValue
if (this.isNotBlank(val)) {
defaultSaveForm[key] = val
}
})
//
this.saveForm = this.deepClone(defaultSaveForm)
console.log('编辑框默认值:' + JSON.stringify(this.saveForm))
},
handleCloseDialog(val) {
//
this.initDefaultSaveForm()
this.showDialog = false, //
this.dialogFullScreen = false, //
this.cardRowColNum = 2, //
this.countForValidJoinForm = 0, //
this.$emit('closeEvent', val)
},
//
handleSetRowColNum(num) {
this.cardRowColNum = num
},
//
getComponentByJoinType(type, item) {
if (type == 'OneToOne') {
return 'EditForm'
} else if (type == 'OneToMany') {
return 'EditTable'
} else {
return ''
}
},
async queryByPrimarykey(rowData) {
const { data, code } = await this.option.buttons.queryByPrimarykey.api(rowData)
if (code != '200') return
this.showDialog = true
this.saveForm = data
},
//
handleValidateAndSave() {
this.countForValidJoinForm = 0
//
this.$refs.mainForm.validate((mainValid) => {
if (mainValid == false) {
console.warn('主表单校验失败')
return
}
console.log('主表单校验完成')
if (this.joinEntitys == null || this.joinEntitys.length == 0) {
//
this.handleSave()
return
}
for (var i = 0; i < this.joinEntitys.length; i++) {
console.log(`开始校验子表单-${i} 校验`)
var item = this.joinEntitys[i]
if (this.$refs['joinForm' + i] == null || item.hide == true || this.saveForm[item.fieldNameInMainEntityOnSave] == null || this.saveForm[item.fieldNameInMainEntityOnSave].length == 0) {
console.log('子表单没有数据,直接跳过')
this.countForValidJoinForm++
console.log('已经校验的子表单:' + this.countForValidJoinForm + ' 共:' + this.joinEntitys.length)
//
if (this.countForValidJoinForm == this.joinEntitys.length) {
console.log('子表单校验完成,提交主表单')
this.handleSave()
}
continue
}
var joinForm = this.$refs['joinForm' + i]
if (toString.call(joinForm) == '[object Array]') {
joinForm = joinForm[0]
}
joinForm.validate((joinValid) => {
if (joinValid) {
this.countForValidJoinForm++
console.log('已经校验的子表单:' + this.countForValidJoinForm + ' 共:' + this.joinEntitys.length)
//
if (this.countForValidJoinForm == this.joinEntitys.length) {
console.log('子表单校验完成,提交主表单')
this.handleSave()
}
} else {
console.warn(`子表单${i}校验失败:`)
}
})
}
})
},
async handleSave() {
//
if (this.modelType == 'add') {
const { code, message } = await this.option.buttons.add.api(this.saveForm)
if (code == '200') {
//
this.handleCloseDialog()
//
this.$emit('closeEvent')
return
} else {
this.countForValidJoinForm = 0, //
console.log(`提交表单调用新增接口失败:${message}`)
}
}
//
if (this.modelType == 'edit') {
// console.log(this.$slots.customCard[0].context.$refs.cardInEditData.updateData.settingValue)
const { code, message } = await this.option.buttons.edit.api(this.saveForm)
if (code == '200') {
//
this.handleCloseDialog()
//
this.$emit('closeEvent')
return
} else {
this.countForValidJoinForm = 0, //
console.log(`提交表单调用更新接口失败:${message}`)
}
}
/*
//
this.$refs.mainForm.handleSave(() => {
//
if (this.countJoinEntityOneToOne == 0) {
//
this.handleCloseDialog()
//
this.$emit('closeEvent')
return
}
//
for (var i = 0; i < this.joinEntitys.length; i++) {
if (this.joinEntitys[i].joinType == 'OneToOne') {
this.$refs['joinForm' + i].handleSave(() => {
this.countForSavedOneToOneJoinEntity++
if (this.countForSavedOneToOneJoinEntity == this.countJoinEntityOneToOne) {
//
this.handleCloseDialog()
//
this.$emit('closeEvent')
}
})
}
}
})*/
},
},
}
</script>
<style scoped lang="scss">
// /deep/.el-dialog__body {
// background-color: rgb(240, 242, 245);
// padding: 5px;
// max-height: 60vh;
// overflow: auto;
// height: calc(100vh - 100px);
// }
.notfull-screen {
/deep/.el-dialog__body {
background-color: rgb(240, 242, 245);
padding: 5px;
max-height: 60vh;
overflow: auto;
}
}
.full-screen {
/deep/.el-dialog__body {
background-color: rgb(240, 242, 245);
padding: 5px;
height: calc(100vh - 110px);
overflow: auto;
}
}
</style>

@ -1,323 +0,0 @@
<!--element下拉列表封装
使用
<hyb-select ref="hybSelect"
url="/v1/orgs"
v-model="search.orgId" option="orgId" label="orgName"
placeholder multiple localOptions></hyb-select>
1.url:要显示的下拉列表数据来源
规范返回的数据要符合(JSON中对应的字段必须label和value,不能其他)
[
{label:'显示1',value:'值1'},
{label:'显示2',value:'值2'},
{label:'显示3',value:'值3'},
...
]
2.v-model数据的双向绑定,绑定父组件中的字段
3.option自定义select的value对应的字段
4.label自定义select的label对应的字段
5.placeholder下拉列表提示
6.multiple是否是多选
7.localOptions使用本地的数据,不用请求远程数据,注意使用该属性时Url属性不能要,不然无效
-->
<template>
<div>
<el-select
v-model="selectValue"
:clearable="clearable"
:collapse-tags="collapseTags"
filterable
class="filter-item"
:placeholder="placeholder"
:disabled="disabled"
:multiple="multiple == null ? false : true"
:remote="remoteFilter"
:remote-method="remoteQuery"
@change="change"
>
<el-option
v-for="(item, index) in options"
:key="index"
:label="getItemLabel(item, label)"
:value="item[option]"
:disabled="isDisabledOption(item)"
>
<template v-if="mergeLabel">
<span style="float: left">{{ getItemLabel(item, label) }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{
item[option]
}}</span>
</template>
</el-option>
<el-option v-if="totalPage > 1" label="搜索更多" value="" disabled />
</el-select>
</div>
</template>
<script>
import request from "@/utils/request";
import { getStorageItem } from "@/utils/storage";
export default {
props: {
dictCode: null, // dictCodeurl
url: null,
method: null,
queryParam: {
type: Object,
default: () => {
return {};
}
},
value: null,
placeholder: null,
label: {
type: String,
default: "text"
},
option: {
type: String,
default: "id"
},
multiple: null,
localOptions: null,
disabled: null,
clearable: {
type: Boolean,
default: true
},
collapseTags: {
type: Boolean,
default: false
},
mergeLabel: {
type: Boolean,
default: false
},
//
disabledOptions: {
type: String,
default: () => {
return "";
}
},
// 使
remoteFilter: {
type: Boolean,
default: false
}
},
data() {
return {
options: null,
selectValue: null,
//
totalPage: 0
};
},
computed: {
// dictCodeurlurl
requestUrl() {
if (this.url != null && this.url.trim() != "") {
if (this.url.indexOf("?") > 0) {
if (this.option == null) {
console.log("url-" + this.url.substring(this.url.indexOf("?")));
}
if (this.label == null) {
}
}
return this.url;
}
if (this.dictCode != null && this.dictCode.trim() != "") {
return `/meta/gaeaDict/select/${this.dictCode}`;
}
return null;
}
},
watch: {
value: function(val, oldVal) {
if (this.multiple != null) {
if (!this.value) {
this.selectValue = [];
} else {
this.selectValue = this.value;
}
} else {
if (this.value != null && this.value != undefined) {
this.selectValue = this.value;
} else {
this.selectValue = "";
}
}
},
url() {
setTimeout(() => {
this.queryData();
}, 500);
}
},
created() {
if (this.multiple != null) {
this.selectValue = this.value;
} else {
if (this.value != null) {
this.selectValue = this.value;
}
}
},
mounted() {
if (this.requestUrl == null) {
this.options = this.localOptions;
return;
}
this.queryData();
},
methods: {
//
isDisabledOption(option) {
if (
option == null ||
this.disabledOptions == null ||
this.disabledOptions.length == 0
) {
return false;
}
var currentOptionVal = option[this.option];
return this.disabledOptions.indexOf(currentOptionVal) >= 0;
},
change(value) {
if (value === "") {
value = null;
}
this.$emit("input", value);
//
var optionItem = this.options.find(item => item[this.option] == value);
this.$emit("change", value, optionItem);
},
// label
getItemLabel(item, label) {
if (label.indexOf("${") < 0 && label.indexOf("}" < 0)) {
return item[label];
}
var reg = /\$\{[a-zA-Z0-9]*\}/g;
var list = label.match(reg);
// ["${id}", "${text}"]
var result = label;
for (var i = 0; i < list.length; i++) {
var sub = list[i];
var key = sub.replace("${", "").replace("}", "");
result = result.replace(sub, item[key]);
}
return result;
},
// localStorage gaeaDict
getOptionsFromLocalStorage() {
var dicts = getStorageItem("gaeaDict");
var options = [];
if (!dicts.hasOwnProperty(this.dictCode)) {
return [];
}
var dictItems = dicts[this.dictCode];
for (var i = 0; i < dictItems.length; i++) {
var dictItem = dictItems[i];
options.push({ id: dictItem.id, text: dictItem.text });
}
return options;
},
queryData() {
// localStorageApp.vue
var options = this.getOptionsFromLocalStorage();
if (this.isNotBlank(options)) {
this.options = options;
return;
}
// localStorage
if (this.requestUrl == null) {
return;
}
if (
this.method != null &&
this.method.toLocaleLowerCase().trim() == "post"
) {
this.queryDataByPost();
} else {
this.queryDataByGet();
}
},
queryDataByGet(keyword) {
var param = this.deepClone(this.queryParam);
if (this.isNotBlank(keyword)) {
param["keyword"] = keyword;
}
param["multiple"] = this.multiple == null ? null : 1;
request({
url: this.requestUrl,
headers: { noPrompt: true },
params: param
}).then(response => {
this.setOptions(response.data);
});
},
queryDataByPost(keyword) {
var param = this.deepClone(this.queryParam);
if (this.isNotBlank(keyword)) {
param["keyword"] = keyword;
}
request({
url: this.requestUrl,
method: "post",
headers: { noPrompt: true },
data: param
}).then(response => {
this.setOptions(response.data);
});
},
setOptions(resData) {
if (resData == null || resData.length == 0) {
this.options = [];
this.totalPage = 0;
return;
}
if (this.isArray(resData)) {
this.options = resData;
this.totalPage = 1;
return;
}
if (
resData.records == null ||
resData.total == null ||
resData.pages == null
) {
this.options = [];
return;
}
this.totalPage = resData.pages;
// resData.records
// resData.total
// resData.size
// resData.current
this.options = resData.records;
},
remoteQuery(keyword) {
if (this.isBlank(keyword)) {
return;
}
setTimeout(() => {
if (
this.method != null &&
this.method.toLocaleLowerCase().trim() == "post"
) {
this.queryDataByPost(keyword);
} else {
this.queryDataByGet(keyword);
}
}, 200);
}
}
};
</script>
<style scoped>
.filter-item {
width: 100%;
}
</style>

@ -1,99 +0,0 @@
<!--
* @Author: lide1202@hotmail.com
* @Date: 2021-5-4 11:04:24
* @Last Modified by: lide1202@hotmail.com
* @Last Modified time: 2021-5-5 11:04:24
!-->
<template>
<div>
<el-input class="filterInput" placeholder="搜索" v-model="filterText" v-if="enableFilter" />
<div class="title">{{ labelName }}</div>
<el-tree ref="table_tree" :data="treeData" node-key="id" :default-expand-all="isOpen" :expand-on-click-node="false" :filter-node-method="filterNode" @node-click="nodeClick" @check="checkedEvent" />
</div>
</template>
<script>
import request from '@/utils/request'
export default {
components: {},
props: {
url: {
type: [String],
default: () => {
return ''
},
},
id: {
type: [String],
default: () => {
return 'id'
},
},
label: {
type: [String],
default: () => {
return ''
},
},
value: {
type: [String],
default: () => {
return ''
},
},
labelName: String,
enableFilter: Boolean,
isOpen: Boolean,
},
data() {
return {
filterText: '',
treeData: [],
}
},
computed: {},
watch: {
filterText(val) {
this.$refs.table_tree.filter(val)
},
},
mounted() {
this.queryData()
},
methods: {
filterNode(val, data) {
if (!val) return true
return data.label.indexOf(val) !== -1
},
queryData() {
if (this.isBlank(this.url)) {
return
}
request({
url: this.url,
method: 'GET',
}).then((response) => {
if (response.code != '200') {
return
}
this.treeData = Object.prototype.toString.call(response.data) == '[object Array]' ? response.data : response.data.tree|| response.data.menuTree
})
},
// tree treeid
nodeClick(node) {
this.$emit('input', node['id'])
this.$emit('node-click', node['id'])
},
checkedEvent(item, evt) {
var ids = evt.checkedKeys.toString()
this.$emit('input', ids)
},
},
}
</script>
<style scoped lang="scss">
.filterInput {
margin-bottom: 20px;
}
</style>

@ -1,161 +0,0 @@
<template>
<div class="uploadImage">
<el-upload
:headers="headers"
:limit="limit"
:action="requestUrl"
list-type="picture-card"
:file-list="fileList"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
:show-file-list="true"
:before-upload="handleBeforeUpload"
:class="fileList && fileList.length >= limit ? 'hide_box' : ''"
>
<i class="el-icon-plus" />
</el-upload>
<el-dialog :visible.sync="dialogVisibleImageUpload" :modal="false">
<img width="100%" :src="imageUploadUrl" alt="" />
</el-dialog>
</div>
</template>
<script>
import { getToken } from "@/utils/auth"; // get token from cookie
export default {
props: {
upLoadUrl: {
type: String,
default: () => {
return "";
}
},
viewUrl: {
type: String,
default: () => {
return process.env.BASE_API + "/file/download/";
}
},
limit: {
type: Number,
default: () => {
return 1;
}
},
value: {
type: String,
default: () => {
return "";
}
}
},
data() {
return {
imageUploadUrl: "",
dialogVisibleImageUpload: false,
fileList: []
};
},
computed: {
requestUrl() {
if (this.upLoadUrl != null && this.upLoadUrl.trim() != "") {
return process.env.BASE_API + this.upLoadUrl;
} else {
return process.env.BASE_API + "/file/upload";
}
},
headers() {
return {
Authorization: getToken() // token
};
}
},
watch: {
value: {
handler(val) {
this.echoUpload(this.value);
},
immediate: true
}
},
mounted() {
this.echoUpload(this.value);
},
methods: {
handleRemove(file) {
this.fileList = [];
this.change();
},
handlePictureCardPreview(file) {
this.imageUploadUrl = file.url;
this.dialogVisibleImageUpload = true;
},
//
handleSuccess(response, file, fileList) {
if (response.code != 200) {
this.$message.error("上传失败");
return;
}
this.fileList.push({
url: file.response.data.urlPath
});
this.change();
},
//
change() {
const fileList = (this.fileList.length > 0 && this.fileList[0].url) || "";
this.$emit("input", fileList);
this.$emit("change", fileList);
},
//
handleBeforeUpload(file) {
const extension = file.name
.split(".")
[file.name.split(".").length - 1].toLowerCase();
// .png|.jpg|.gif|.icon|.pdf|.xlsx|.xls|.csv|.mp4|.avi
const extensionList = ["png", "jpg", "gif", "icon"];
if (extensionList.indexOf(extension) < 0) {
this.$message.warning("请上传正确的格式文件");
return false;
}
return true;
},
//
echoUpload(val) {
if (!val) {
this.fileList = [];
} else {
const list = [{ url: val }];
this.fileList = list;
}
}
}
};
</script>
<style lang="scss" scoped>
.uploadImage .el-upload--picture-card {
width: 60px;
height: 60px;
line-height: 65px;
}
.uploadImage .el-upload-list__item {
width: 60px;
height: 60px;
}
.hide_box /deep/ .el-upload--picture-card {
display: none;
}
.el-upload-list__item {
line-height: 1.5;
}
.el-upload-list--picture-card .el-upload-list__item-actions {
text-align: left;
display: flex;
flex-wrap: wrap;
}
.imgBox,
.iconFont {
width: 100% !important;
height: 100% !important;
}
</style>
Loading…
Cancel
Save