fix org对seed的错误应用

This commit is contained in:
2021-05-09 13:04:52 +08:00
parent 982b79bbb0
commit 57e1a4231d
7 changed files with 91 additions and 403 deletions

View File

@@ -95,6 +95,8 @@
box-shadow: 0 0 0 2px @white; box-shadow: 0 0 0 2px @white;
} }
&--name { &--name {
font-weight: bolder;
position: absolute; position: absolute;
left: 32px + @padding-sm * 2; left: 32px + @padding-sm * 2;

View File

@@ -1,71 +0,0 @@
<template>
<a-modal
:confirmLoading="confirmLoading"
:visible="visible"
@cancel="onCancel"
@ok="onOk"
class="yo-modal-form"
title="新增应用"
>
<FormBody ref="form-body" />
</a-modal>
</template>
<script>
import FormBody from './form';
export default {
components: {
FormBody,
},
data() {
return {
visible: false,
confirmLoading: false,
};
},
methods: {
/**
* 必要的方法
* 从外部调用打开本窗口
*/
onOpen() {
this.visible = true;
},
/**
* 必要的方法
* 点击保存时的操作
*/
onOk() {
this.$refs['form-body'].onValidate((valid) => {
if (valid) {
this.confirmLoading = true;
this.$api
.sysAppAdd(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) {
this.$message.success('新增成功');
this.onCancel();
this.$emit('ok');
}
})
.finally(() => {
this.confirmLoading = false;
});
}
});
},
/**
* 必要的方法
* 关闭窗口时的操作
*/
onCancel() {
this.$refs['form-body'].onResetFields();
this.visible = false;
},
},
};
</script>

View File

@@ -1,74 +0,0 @@
<template>
<a-modal
:confirmLoading="confirmLoading"
:visible="visible"
@cancel="onCancel"
@ok="onOk"
class="yo-modal-form"
title="编辑应用"
>
<FormBody ref="form-body" />
</a-modal>
</template>
<script>
import FormBody from './form';
export default {
components: {
FormBody,
},
data() {
return {
visible: false,
confirmLoading: false,
};
},
methods: {
/**
* 必要的方法
* 从外部调用打开本窗口,并填充外部传入的数据
*/
onOpen(record) {
this.visible = true;
this.$nextTick(() => {
this.$refs['form-body'].onFillData(record);
});
},
/**
* 必要的方法
* 点击保存时的操作
*/
onOk() {
this.$refs['form-body'].onValidate((valid) => {
if (valid) {
this.confirmLoading = true;
this.$api
.sysAppEdit(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) {
this.$message.success('编辑成功');
this.onCancel();
this.$emit('ok');
}
})
.finally(() => {
this.confirmLoading = false;
});
}
});
},
/**
* 必要的方法
* 关闭窗口时的操作
*/
onCancel() {
this.$refs['form-body'].onResetFields();
this.visible = false;
},
},
};
</script>

View File

@@ -1,84 +0,0 @@
<template>
<a-drawer
:confirmLoading="confirmLoading"
:visible="visible"
:width="800"
@close="onClose"
@ok="onOk"
class="yo-drawer-form"
title="新增菜单"
>
<FormBody ref="form-body" />
<div class="ant-drawer-footer">
<a-button @click="onClose">取消</a-button>
<a-button :loading="confirmLoading" @click="onOk" type="primary">确定</a-button>
</div>
</a-drawer>
</template>
<script>
import FormBody from './form';
export default {
components: {
FormBody,
},
data() {
return {
visible: false,
confirmLoading: false,
};
},
computed: {
formBody() {
return this.$refs['form-body'];
},
},
methods: {
/**
* 必要的方法
* 从外部调用打开本窗口
*/
async onOpen(record) {
this.visible = true;
this.$nextTick(async () => {
await this.formBody.onInit(record, true);
});
},
/**
* 必要的方法
* 点击保存时的操作
*/
onOk() {
this.formBody.onGetData().then((data) => {
this.confirmLoading = true;
this.$api
.sysMenuAdd(data)
.then(({ success }) => {
if (success) {
this.$message.success('新增成功');
this.onClose();
this.$emit('ok');
}
})
.finally(() => {
this.confirmLoading = false;
});
});
},
/**
* 必要的方法
* 关闭窗口时的操作
*/
onClose() {
this.formBody.onResetFields();
this.visible = false;
},
},
};
</script>

View File

@@ -1,83 +0,0 @@
<template>
<a-drawer
:confirmLoading="confirmLoading"
:visible="visible"
:width="800"
@close="onClose"
class="yo-drawer-form"
title="编辑应用"
>
<FormBody ref="form-body" />
<div class="ant-drawer-footer">
<a-button @click="onClose">取消</a-button>
<a-button :loading="confirmLoading" @click="onOk" type="primary">确定</a-button>
</div>
</a-drawer>
</template>
<script>
import FormBody from './form';
export default {
components: {
FormBody,
},
data() {
return {
visible: false,
confirmLoading: false,
};
},
computed: {
formBody() {
return this.$refs['form-body'];
},
},
methods: {
/**
* 必要的方法
* 从外部调用打开本窗口,并填充外部传入的数据
*/
onOpen(record) {
this.visible = true;
this.$nextTick(async () => {
await this.formBody.onInit(record);
this.formBody.onFillData(record);
});
},
/**
* 必要的方法
* 点击保存时的操作
*/
onOk() {
this.formBody.onGetData().then((data) => {
this.confirmLoading = true;
this.$api
.sysMenuEdit(data)
.then(({ success }) => {
if (success) {
this.$message.success('编辑成功');
this.onClose();
this.$emit('ok');
}
})
.finally(() => {
this.confirmLoading = false;
});
});
},
/**
* 必要的方法
* 关闭窗口时的操作
*/
onClose() {
this.formBody.onResetFields();
this.visible = false;
},
},
};
</script>

View File

@@ -11,7 +11,7 @@
<div class="yo-form-group"> <div class="yo-form-group">
<!-- 表单控件 --> <!-- 表单控件 -->
<!-- ... --> <!-- ... -->
<a-form-model-item label="机构名称" prop="name"> <a-form-model-item label="机构名称" prop="name">
<a-input placeholder="请输入机构名称" v-model="form.name" /> <a-input placeholder="请输入机构名称" v-model="form.name" />
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="唯一编码" prop="code"> <a-form-model-item label="唯一编码" prop="code">
@@ -57,16 +57,15 @@ import { EMPTY_ID } from '@/util/global';
/* 表单内容默认值 */ /* 表单内容默认值 */
const defaultForm = { const defaultForm = {
/* ... */ /* ... */
pid: undefined,
sort: 100,
}; };
export default { export default {
data() { data() {
return { return {
/** 表单数据 */ /** 表单数据 */
form: { form: {},
pid: undefined,
sort: 100,
},
/** 验证格式 */ /** 验证格式 */
rules: { rules: {
name: [{ required: true, message: '请输入机构名称' }], name: [{ required: true, message: '请输入机构名称' }],
@@ -90,45 +89,42 @@ export default {
* 必要的方法 * 必要的方法
* 在打开编辑页时允许填充数据 * 在打开编辑页时允许填充数据
*/ */
onFillData(params,orgId) { onFillData(params) {
if(orgId){ // 从字符串areaCode查找到整个层级
this.form.pid = orgId; const areaCode = [];
}else if(params){ const findCode = (data, level) => {
// 从字符串areaCode查找到整个层级 level = level || 0;
const areaCode = []; for (let i = 0; i < data.length; i++) {
const findCode = (data, level) => { const item = data[i];
level = level || 0; areaCode[level] = item.code;
for (let i = 0; i < data.length; i++) {
const item = data[i];
areaCode[level] = item.code;
if (item.code === params.areaCode) { if (item.code === params.record.areaCode) {
areaCode.length = level + 1; areaCode.length = level + 1;
return true;
}
if (item.children && item.children.length) {
const found = findCode(item.children, level + 1);
if (found) {
return true; return true;
} }
if (item.children && item.children.length) {
const found = findCode(item.children, level + 1);
if (found) {
return true;
}
}
} }
};
if (params.areaCode) {
findCode(this.areaData);
} }
};
if (params.record && params.record.areaCode) {
findCode(this.areaData);
}
/** 将默认数据覆盖到form */ /** 将默认数据覆盖到form */
this.form = this.$_.cloneDeep({ this.form = this.$_.cloneDeep({
...defaultForm, ...defaultForm,
...params, pid: params.orgId,
areaCode, ...params.record,
/** 在此处添加其他默认数据转换 */ /** 在此处添加其他默认数据转换 */
/* ... */ /* ... */
areaCode,
}); });
}
}, },
/** /**
@@ -137,14 +133,13 @@ export default {
*/ */
onGetData() { onGetData() {
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
const record = this.$_.cloneDeep(this.form); const record = this.$_.cloneDeep(this.form);
record.areaCode = record.areaCode[record.areaCode.length - 1]; record.areaCode = record.areaCode[record.areaCode.length - 1];
/** 验证通过后可以对数据进行转换得到想要提交的格式 */ /** 验证通过后可以对数据进行转换得到想要提交的格式 */
/* ... */ /* ... */
reslove(record); reslove(record);
} else { } else {
reject(); reject();
@@ -182,7 +177,7 @@ export default {
this.loading = true; this.loading = true;
/** 可以在这里await获取一些异步数据 */ /** 可以在这里await获取一些异步数据 */
await this.onLoadOrgData(); await this.onLoadOrgData();
await this.onLoadAreaData(); await this.onLoadAreaData();
/* ... */ /* ... */
this.loading = false; this.loading = false;
}, },

View File

@@ -5,63 +5,68 @@
2021-04-30 2021-04-30
Lufthafen Lufthafen
--> -->
<yo-tree-layout <yo-tree-layout
:load-data="loadTreeData" :load-data="loadTreeData"
@select="onSelect" @select="onSelect"
default-expanded-keys default-expanded-keys
ref="tree-layout" ref="tree-layout"
> >
<container> <container>
<br /> <br />
<a-card :bordered="false"> <a-card :bordered="false">
<yo-table <yo-table
:columns="columns" :columns="columns"
:load-data="loadData" :load-data="loadData"
@query="onQuery" @query="onQuery"
@resetQuery="onResetQuery" @resetQuery="onResetQuery"
ref="table" ref="table"
> >
<Auth auth="sysOrg:page" slot="query"> <Auth auth="sysOrg:page" slot="query">
<!-- 此处添加查询表单控件 --> <!-- 此处添加查询表单控件 -->
<!-- ... -->
<a-form-model-item label="机构名称">
<a-input allow-clear placeholder="请输入机构名称" v-model="query.name" />
</a-form-model-item>
</Auth>
<Auth auth="sysOrg:add" slot="operator">
<a-button @click="onOpen('add-form')" icon="plus">新增机构</a-button>
</Auth>
<!-- 格式化字段内容 -->
<!-- ... -->
<!-- 添加操作控件 -->
<span slot="action" slot-scope="text, record">
<yo-table-actions>
<Auth auth="sysOrg:edit">
<a @click="onOpen('edit-form', record)">编辑</a>
</Auth>
<Auth auth="sysOrg:delete">
<a-popconfirm @confirm="onDelete(record)" placement="topRight" title="是否确认删除">
<a>删除</a>
</a-popconfirm>
</Auth>
<!-- 可在此处添加其他操作控件 -->
<!-- ... --> <!-- ... -->
</yo-table-actions> <a-form-model-item label="机构名称">
</span> <a-input allow-clear placeholder="请输入机构名称" v-model="query.name" />
</yo-table> </a-form-model-item>
</a-card> </Auth>
<Auth auth="sysOrg:add" slot="operator">
<a-button @click="onOpen('add-form')" icon="plus">新增机构</a-button>
</Auth>
<!-- 格式化字段内容 -->
<!-- ... -->
<!-- 添加操作控件 -->
<span slot="action" slot-scope="text, record">
<yo-table-actions>
<Auth auth="sysOrg:edit">
<a @click="onOpen('edit-form', record)">编辑</a>
</Auth>
<Auth auth="sysOrg:delete">
<a-popconfirm @confirm="onDelete(record)" placement="topRight" title="是否确认删除">
<a>删除</a>
</a-popconfirm>
</Auth>
<!-- 可在此处添加其他操作控件 -->
<!-- ... -->
</yo-table-actions>
</span>
</yo-table>
</a-card>
<!-- 新增表单 --> <!-- 新增表单 -->
<yo-modal-form :action="$api[api.add]" :title="'新增' + name" @ok="onReloadData" ref="add-form"> <yo-modal-form :action="$api[api.add]" :title="'新增' + name" @ok="onReloadData" ref="add-form">
<form-body /> <form-body />
</yo-modal-form> </yo-modal-form>
<!-- 编辑表单 --> <!-- 编辑表单 -->
<yo-modal-form :action="$api[api.edit]" :title="'编辑' + name" @ok="onReloadData" ref="edit-form"> <yo-modal-form
<form-body /> :action="$api[api.edit]"
</yo-modal-form> :title="'编辑' + name"
</container> @ok="onReloadData"
</yo-tree-layout> ref="edit-form"
>
<form-body />
</yo-modal-form>
</container>
</yo-tree-layout>
</template> </template>
<script> <script>
import FormBody from './form'; import FormBody from './form';
@@ -167,7 +172,7 @@ export default {
*/ */
onResetQuery() { onResetQuery() {
/** 在这里重置查询条件时,可对特殊的字段做保留处理 */ /** 在这里重置查询条件时,可对特殊的字段做保留处理 */
Object.keys(this.query).forEach((p) => { Object.keys(this.query).forEach((p) => {
if (p !== 'pid') { if (p !== 'pid') {
this.query[p] = undefined; this.query[p] = undefined;
} }
@@ -219,14 +224,12 @@ export default {
* 从列表页调用窗口的打开方法 * 从列表页调用窗口的打开方法
*/ */
onOpen(formName, record) { onOpen(formName, record) {
this.$refs[formName].onOpen( this.$refs[formName].onOpen({
record, record,
/* 按需添加其他参数 */ /* 按需添加其他参数 */
/* ... */ /* ... */
orgId: this.query['pid'],
this.query['pid'] });
);
}, },
/** /**
* 必要方法 * 必要方法