This commit is contained in:
ky_sunl
2021-04-20 02:57:07 +00:00
parent 1bd0b90a2d
commit 7504c9b75c
21 changed files with 484 additions and 229 deletions

View File

@@ -1,15 +1,20 @@
@import (reference) '~@/assets/style/extend.less'; @import (reference) '~@/assets/style/extend.less';
.yo-query-bar { .yo-query-bar {
margin-bottom: @padding-md; margin-bottom: @padding-md;
} }
.yo-action-bar { .yo-action-bar {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-bottom: @padding-md; margin-bottom: @padding-md;
&--actions { &--actions {
>.ant-btn, >.ant-btn,
>.ant-btn-group { >.ant-btn-group {
+.ant-btn, +.ant-btn,
+.ant-btn-group { +.ant-btn-group {
margin-left: @padding-xs; margin-left: @padding-xs;
@@ -17,16 +22,20 @@
} }
} }
} }
.ant-table { .ant-table {
background-color: @white; background-color: @white;
.yo-action-bar { .yo-action-bar {
margin-bottom: 0; margin-bottom: 0;
} }
} }
.ant-table-small { .ant-table-small {
>.ant-table-content { >.ant-table-content {
>.ant-table-body { >.ant-table-body {
margin: 0; margin: 0;
>table { >table {
>.ant-table-thead { >.ant-table-thead {
>tr { >tr {
@@ -39,6 +48,7 @@
} }
} }
} }
.ant-table-thead { .ant-table-thead {
>tr { >tr {
>th { >th {
@@ -46,15 +56,20 @@
} }
} }
} }
.yo-table { .yo-table {
.border-right-none { .border-right-none() {
border-right-width: 0; border-right-width: 0 !important;
&:last-child { &:last-child {
border-right-width: 1px; border-right-width: 1px !important;
} }
} }
.ant-table-content { .ant-table-content {
>.ant-table-body { .ant-table-body {
overflow-x: auto !important;
>table { >table {
>.ant-table-thead { >.ant-table-thead {
>tr { >tr {
@@ -63,6 +78,7 @@
} }
} }
} }
>.ant-table-tbody { >.ant-table-tbody {
>tr { >tr {
>td { >td {
@@ -72,19 +88,82 @@
} }
} }
} }
.ant-table-fixed-left {
.ant-table-thead {
>tr {
>th {
border-right-width: 0 !important;
} }
} }
}
.ant-table-tbody {
>tr {
>td {
border-right-width: 0 !important;
}
}
}
}
.ant-table-fixed-right {
.ant-table-fixed {
border-left-width: 0 !important;
}
.ant-table-thead {
>tr {
>th {
.border-right-none();
}
}
}
.ant-table-tbody {
>tr {
>td {
.border-right-none();
}
}
}
}
}
}
.yo-table-actions { .yo-table-actions {
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
&--inner { &--inner {
display: flex; display: flex;
align-items: center; align-items: center;
height: 18px; height: 18px;
>a { >a {
color: darken(@primary-color, 20%); color: darken(@primary-color, 20%);
} }
} }
} }
.yo-table--column-setting {
width: 240px;
.ant-dropdown-menu-item {
display: flex;
justify-content: space-between;
align-items: center;
}
.anticon-pushpin {
color: darken(@white, 40%);
transition: @animation-duration-slow;
transform: rotate(45deg);
}
.yo-table--fixed {
transform: rotate(-45deg);
}
}

View File

@@ -18,7 +18,7 @@ axios.defaults.baseURL = '/api'
*/ */
import urls from './requests' import urls from './requests'
const initInstance = function () { const initInstance = () => {
const instance = axios const instance = axios
.create({ .create({
headers: { headers: {
@@ -40,6 +40,27 @@ const initInstance = function () {
return instance return instance
} }
const errorNotification = ({ code, message }) => {
switch (message.constructor) {
case Array:
message.map(p => {
app.$notification.error({
duration: 0,
message: p.field,
description: p.messages.join('/'),
})
})
break
default:
app.$notification.error({
duration: 0,
message: code || '错误',
description: message,
})
break
}
}
const api = {} const api = {}
for (let key in urls) { for (let key in urls) {
@@ -75,24 +96,22 @@ for (let key in urls) {
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
api[`${key}Wait`](params) api[`${key}Wait`](params)
.then(({ data }) => { .then(({ data }) => {
if ([status.BadRequest].indexOf(data.code) >= 0) {
errorNotification(data)
reject(data)
} else {
reslove(data) reslove(data)
}
}) })
.catch(({ response: { data } }) => { .catch(({ response: { data } }) => {
const { code, message } = data if (process.env.VUE_APP_NODE_ENV === 'development') {
app.$notification.error({ errorNotification({
duration: 0, message: '发生错误,请联系管理员'
message: code,
description: message,
}) })
} else {
// if (process.env.VUE_APP_NODE_ENV === 'development') { errorNotification(data)
// app.$notification.open({ reject(data)
// message: '错误', }
// description: '发生错误,请联系管理员',
// });
// } else {
// reject(err, urls[key])
// }
}) })
}) })
} }

View File

@@ -127,7 +127,6 @@ const authByJson = (auth, permissions) => {
export const auth = (auth) => { export const auth = (auth) => {
const { info } = app.global const { info } = app.global
const permissions = info.permissions
if (!info) { if (!info) {
return false return false
@@ -140,6 +139,8 @@ export const auth = (auth) => {
return true return true
} }
const permissions = info.permissions
let flag = false let flag = false
if (auth) { if (auth) {

View File

@@ -0,0 +1,64 @@
<template>
<a-dropdown :trigger="['click']" placement="bottomRight" v-model="visible">
<a-button>显示列</a-button>
<a-menu @click="() => { return false; }" class="yo-table--column-setting" slot="overlay">
<a-menu-item>
<a-checkbox :checked="checkedAll" :indeterminate="halfChecked" @change="onCheckAll">全选</a-checkbox>
</a-menu-item>
<a-menu-divider />
<a-menu-item :key="column.dataIndex || column.key" v-for="column in columns">
<a-checkbox :checked="!column.hidden" @change="(e) => onCheck(column, e)">{{column.title}}</a-checkbox>
<a-icon
:class="{ 'yo-table--fixed': column.fixed }"
@click="onFixed(column)"
type="pushpin"
/>
</a-menu-item>
</a-menu>
</a-dropdown>
</template>
<script>
export default {
props: {
columns: {
type: Array,
require: true,
},
},
data() {
return {
visible: false,
checkedAll: true,
halfChecked: false,
};
},
mounted() {
this.onHalfCheck();
},
methods: {
onHalfCheck() {
this.halfChecked = this.columns.filter((p) => p.hidden).length > 0;
},
onCheck(column, e) {
this.$set(column, 'hidden', !e.target.checked);
this.onHalfCheck();
},
onCheckAll(e) {
this.columns.forEach((column) => {
this.$set(column, 'hidden', !e.target.checked);
});
this.checkedAll = e.target.checked;
},
onFixed(column) {
this.$set(column, 'fixed', !column.fixed);
},
},
};
</script>

View File

@@ -1,4 +1,5 @@
import { template } from "lodash"; // 列设置用jsx实现起来较为困难
import ColumnSetting from './column'
export default { export default {
props: { props: {
@@ -39,7 +40,9 @@ export default {
sorter: { sorter: {
sortField: '', sortField: '',
sortOrder: '', sortOrder: '',
} },
columnSettingVisible: false
}; };
}, },
@@ -49,6 +52,37 @@ export default {
methods: { methods: {
renderColumnSetting() {
const props = {
visible: this.columnSettingVisible,
placement: 'bottomRight'
}
const on = {
visibleChange: (visible) => {
this.columnSettingVisible = visible
}
}
return (
<a-dropdown {...{ props, on }}>
<a-button onClick={() => this.columnSettingVisible = true}>设置列</a-button>
<a-menu slot="overlay" onClick={() => { return false }}>
{
this.columns.map(column => {
return (
<a-menu-item key={column.dataIndex || column.key}>
<a-checkbox checked={column.hidden} onChange={() => { column.hidden = !column.hidden }}>{column.title}</a-checkbox>
</a-menu-item>
)
})
}
</a-menu>
</a-dropdown>
)
},
onLoading() { onLoading() {
this.loading = { this.loading = {
indicator: <a-icon type="loading" spin /> indicator: <a-icon type="loading" spin />
@@ -74,7 +108,7 @@ export default {
}, },
onReloadData(refresh = false) { onReloadData(refresh = false) {
if (refresh) { if (refresh && refresh.constructor === Boolean) {
this.pagination.current = this.pageNo this.pagination.current = this.pageNo
this.pagination.pageSize = this.pageSize this.pagination.pageSize = this.pageSize
} }
@@ -93,22 +127,37 @@ export default {
loading: this.loading, loading: this.loading,
pagination: this.pagination, pagination: this.pagination,
dataSource: this.data, dataSource: this.data,
columns: this.columns, columns: this.columns.filter(p => !p.hidden),
bordered: true, bordered: true,
size: 'middle', size: 'middle',
rowKey: record => record.id rowKey: record => record.id,
scroll: { x: 'max-content' }
} }
const on = { const on = {
change: this.onTableChange change: this.onTableChange
} }
return ( return (
<section> <section>
<a-alert type="error" closable> <a-alert type="warning" closable>
<template slot="message">后端没有排序参数</template> <template slot="message">
后端没有排序参数
<br />
字段固定应该遵循左侧固定到最左,右侧固定到最右(此逻辑难以实现)
</template>
</a-alert> </a-alert>
<br /> <br />
<div class="yo-action-bar">
<div class="yo-action-bar--actions">
{this.$scopedSlots.operator && this.$scopedSlots.operator()}
</div>
<div class="yo-action-bar--actions">
<a-button-group>
<a-button onClick={this.onReloadData}>刷新</a-button>
<ColumnSetting {...{ props: { columns: this.columns } }} />
</a-button-group>
</div>
</div>
<a-table class="yo-table" {...{ props, on, scopedSlots: { ...this.$scopedSlots } }}> <a-table class="yo-table" {...{ props, on, scopedSlots: { ...this.$scopedSlots } }}>
{Object.keys(this.$slots).map((name) => ( {Object.keys(this.$slots).map((name) => (
<template slot={name}>{this.$slots[name]}</template> <template slot={name}>{this.$slots[name]}</template>

View File

@@ -37,6 +37,7 @@ export default {
this.loadData().then((res) => { this.loadData().then((res) => {
const data = this.generateKey(res) const data = this.generateKey(res)
this.list = []
this.generateList(data) this.generateList(data)
if (this.defaultExpandedKeys) { if (this.defaultExpandedKeys) {
this.expandedKeys = this.list.map(p => p.key) this.expandedKeys = this.list.map(p => p.key)

View File

@@ -68,6 +68,14 @@ const app = new Vue({
* 可通过this.$root.global调用 * 可通过this.$root.global调用
*/ */
global: { global: {
defaultWindow: [{
title: '首页',
path: '/home',
icon: 'home',
closable: false,
}],
/** /**
* 用于存储用户信息 * 用于存储用户信息
*/ */

View File

@@ -42,15 +42,17 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysAppAdd(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysAppAdd(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('新增成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -45,15 +45,17 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysAppEdit(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysAppEdit(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('新增成功'); this.$message.success('编辑成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -22,11 +22,9 @@
</Auth> </Auth>
<yo-table :columns="columns" :load-data="loadData" ref="table"> <yo-table :columns="columns" :load-data="loadData" ref="table">
<div class="yo-action-bar" slot="title"> <Auth auth="sysApp:add" slot="operator">
<div class="yo-action-bar--actions"> <a-button @click="onOpen('add-form')" icon="plus">新增应用</a-button>
<a-button @click="onOpen('add-form')">新增应用</a-button> </Auth>
</div>
</div>
<span slot="active" slot-scope="text, record"> <span slot="active" slot-scope="text, record">
{{ bindCodeValue(text, 'yes_or_no') }} {{ bindCodeValue(text, 'yes_or_no') }}
<Auth auth="sysApp:setAsDefault" v-if="record.active == 'N'"> <Auth auth="sysApp:setAsDefault" v-if="record.active == 'N'">
@@ -101,14 +99,6 @@ export default {
title: '排序', title: '排序',
dataIndex: 'sort', dataIndex: 'sort',
}, },
{
title: '操作',
width: '200px',
dataIndex: 'action',
scopedSlots: {
customRender: 'action',
},
},
], ],
codes: [ codes: [
{ {
@@ -124,6 +114,19 @@ export default {
}, },
created() { created() {
this.onLoadCodes(); this.onLoadCodes();
const flag = this.$auth({
sysApp: [['edit'], ['delete']],
});
if (flag) {
this.columns.push({
title: '操作',
width: '150px',
dataIndex: 'action',
scopedSlots: { customRender: 'action' },
});
}
}, },
methods: { methods: {
/** /**
@@ -187,27 +190,25 @@ export default {
this.$refs[formName].onOpen(record); this.$refs[formName].onOpen(record);
}, },
onResult(success, message, successMessage) { onResult(success, successMessage) {
if (success) { if (success) {
this.$message.success(successMessage); this.$message.success(successMessage);
this.onReloadData(); this.onReloadData();
} else {
this.$refs.table.onLoaded();
this.$message.error(message);
} }
this.$refs.table.onLoaded();
}, },
onSetDefault(record) { onSetDefault(record) {
this.$refs.table.onLoading(); this.$refs.table.onLoading();
this.$api.sysAppSetAsDefault({ id: record.id }).then(({ success, message }) => { this.$api.sysAppSetAsDefault({ id: record.id }).then(({ success }) => {
this.onResult(success, message, '设置成功'); this.onResult(success, '设置成功');
}); });
}, },
onDelete(record) { onDelete(record) {
this.$refs.table.onLoading(); this.$refs.table.onLoading();
this.$api.sysAppDelete(record).then(({ success, message }) => { this.$api.sysAppDelete(record).then(({ success }) => {
this.onResult(success, message, '删除成功'); this.onResult(success, '删除成功');
}); });
}, },
}, },

View File

@@ -5,7 +5,7 @@
@cancel="onCancel" @cancel="onCancel"
@ok="onOk" @ok="onOk"
class="yo-modal-form" class="yo-modal-form"
title="新增应用" title="新增机构"
> >
<FormBody ref="form-body" /> <FormBody ref="form-body" />
</a-modal> </a-modal>
@@ -25,13 +25,27 @@ export default {
}; };
}, },
computed: {
formBody() {
return this.$refs['form-body'];
},
},
methods: { methods: {
/** /**
* 必要的方法 * 必要的方法
* 从外部调用打开本窗口 * 从外部调用打开本窗口
*/ */
onOpen() { onOpen(record, orgId) {
this.visible = true; this.visible = true;
this.$nextTick(async () => {
await this.formBody.onInit();
// 获取外部选中的部门id
this.formBody.onFillData({
pid: orgId,
});
});
}, },
/** /**
@@ -42,15 +56,17 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysAppAdd(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysOrgAdd(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('新增成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -5,7 +5,7 @@
@cancel="onCancel" @cancel="onCancel"
@ok="onOk" @ok="onOk"
class="yo-modal-form" class="yo-modal-form"
title="编辑应用" title="编辑机构"
> >
<FormBody ref="form-body" /> <FormBody ref="form-body" />
</a-modal> </a-modal>
@@ -32,7 +32,8 @@ export default {
*/ */
onOpen(record) { onOpen(record) {
this.visible = true; this.visible = true;
this.$nextTick(() => { this.$nextTick(async () => {
await this.$refs['form-body'].onInit();
this.$refs['form-body'].onFillData(record); this.$refs['form-body'].onFillData(record);
}); });
}, },
@@ -45,15 +46,17 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysAppEdit(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysOrgEdit(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('新增成功'); this.$message.success('编辑成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -1,12 +1,22 @@
<template> <template>
<a-form-model :model="form" :rules="rules" class="yo-form" ref="form"> <a-form-model :model="form" :rules="rules" class="yo-form" ref="form">
<a-spin :spinning="loading">
<a-icon slot="indicator" spin type="loading" />
<div class="yo-form-group"> <div class="yo-form-group">
<a-form-model-item label="机构名称" prop="name"> <a-form-model-item has-feedback 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 has-feedback label="唯一编码" prop="code">
<a-input placeholder="请输入唯一编码" v-model="form.code" /> <a-input placeholder="请输入唯一编码" v-model="form.code" />
</a-form-model-item> </a-form-model-item>
<a-form-model-item has-feedback label="上级机构" prop="pid">
<a-tree-select
:tree-data="orgData"
placeholder="请选择上级机构"
tree-default-expand-all
v-model="form.pid"
/>
</a-form-model-item>
<a-form-model-item label="排序" prop="sort"> <a-form-model-item label="排序" prop="sort">
<a-input-number <a-input-number
:max="1000" :max="1000"
@@ -17,22 +27,26 @@
/> />
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="备注"> <a-form-model-item label="备注">
<a-input placeholder="请输入备注" v-model="form.remark" /> <a-textarea placeholder="请输入备注" v-model="form.remark" />
</a-form-model-item> </a-form-model-item>
</div> </div>
</a-spin>
</a-form-model> </a-form-model>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
form: { form: {},
active: 'N',
},
rules: { rules: {
name: [{ required: true, message: '请输入机构名称' }], name: [{ required: true, message: '请输入机构名称' }],
code: [{ required: true, message: '请输入唯一编码' }], code: [{ required: true, message: '请输入唯一编码' }],
pid: [{ required: true, message: '请选择上级机构' }],
}, },
loading: false,
orgData: [],
}; };
}, },
methods: { methods: {
@@ -61,6 +75,22 @@ export default {
this.$refs.form.resetFields(); this.$refs.form.resetFields();
}, 300); }, 300);
}, },
async onInit() {
this.loading = true;
this.orgData = await this.onLoadOrgData();
this.loading = false;
},
onLoadOrgData() {
return this.$api.getOrgTree().then(({ data }) => {
return data;
});
},
onChangeExtData(value, record, type) {
record[type] = value;
},
}, },
}; };
</script> </script>

View File

@@ -1,9 +1,14 @@
<template> <template>
<yo-tree-layout :load-data="loadTreeData" @select="onSelect" default-expanded-keys> <yo-tree-layout
:load-data="loadTreeData"
@select="onSelect"
default-expanded-keys
ref="tree-layout"
>
<container> <container>
<br /> <br />
<a-card :bordered="false"> <a-card :bordered="false">
<Auth auth="sysUser:page"> <Auth auth="sysOrg:page">
<div class="yo-query-bar"> <div class="yo-query-bar">
<a-form-model :model="query" layout="inline"> <a-form-model :model="query" layout="inline">
<a-form-model-item label="机构名称"> <a-form-model-item label="机构名称">
@@ -19,6 +24,9 @@
</div> </div>
<yo-table :columns="columns" :load-data="loadData" ref="table"> <yo-table :columns="columns" :load-data="loadData" ref="table">
<Auth auth="sysOrg:add" slot="operator">
<a-button @click="onOpen('add-form')" icon="plus">新增机构</a-button>
</Auth>
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
<yo-table-actions> <yo-table-actions>
<Auth auth="sysOrg:edit"> <Auth auth="sysOrg:edit">
@@ -58,14 +66,17 @@ export default {
columns: [ columns: [
{ {
title: '机构名称', title: '机构名称',
width: '400px',
dataIndex: 'name', dataIndex: 'name',
}, },
{ {
title: '唯一编码', title: '唯一编码',
width: '200px',
dataIndex: 'code', dataIndex: 'code',
}, },
{ {
title: '排序', title: '排序',
width: '80px',
dataIndex: 'sort', dataIndex: 'sort',
}, },
{ {
@@ -147,6 +158,7 @@ export default {
*/ */
onReloadData() { onReloadData() {
this.$refs.table.onReloadData(); this.$refs.table.onReloadData();
this.$refs['tree-layout'].onReloadData();
}, },
/** /**
@@ -158,12 +170,13 @@ export default {
}, },
onDelete(record) { onDelete(record) {
this.$api.sysOrgDelete(record).then(({ success, message }) => { this.$api.sysOrgDelete(record).then(({ success }) => {
if (success) { if (success) {
this.$message.success('删除成功'); this.$message.success('删除成功');
this.onReloadData(); this.onReloadData();
} else { if (this.query['pid'] == record.id) {
this.$message.error(message); delete this.query.pid;
}
} }
}); });
}, },

View File

@@ -41,15 +41,18 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysRoleAdd(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
.sysRoleAdd(this.$refs['form-body'].form)
.then(({ success }) => {
this.confirmLoading = false; this.confirmLoading = false;
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('编辑成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -45,15 +45,18 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysRoleEdit(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
.sysRoleEdit(this.$refs['form-body'].form)
.then(({ success }) => {
this.confirmLoading = false; this.confirmLoading = false;
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('编辑成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -2,7 +2,7 @@
<container> <container>
<br /> <br />
<a-card :bordered="false"> <a-card :bordered="false">
<Auth auth="sysApp:page"> <Auth auth="sysRole:page">
<div class="yo-query-bar"> <div class="yo-query-bar">
<a-form-model :model="query" layout="inline"> <a-form-model :model="query" layout="inline">
<a-form-model-item label="角色名称"> <a-form-model-item label="角色名称">
@@ -22,35 +22,33 @@
</Auth> </Auth>
<yo-table :columns="columns" :load-data="loadData" ref="table"> <yo-table :columns="columns" :load-data="loadData" ref="table">
<div class="yo-action-bar" slot="title"> <Auth auth="sysRole:add" slot="operator">
<div class="yo-action-bar--actions"> <a-button @click="onOpen('add-form')" icon="plus">新建角色</a-button>
<a-button @click="onOpen('add-form')">新建角色</a-button> </Auth>
</div>
</div>
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
<yo-table-actions> <yo-table-actions>
<Auth auth="sysApp:edit"> <Auth auth="sysRole:edit">
<a @click="onOpen('edit-form', record)">编辑</a> <a @click="onOpen('edit-form', record)">编辑</a>
</Auth> </Auth>
<Auth auth="sysApp:delete"> <Auth auth="sysRole:delete">
<a-popconfirm @confirm="onDelete(record)" placement="topRight" title="是否确认删除"> <a-popconfirm @confirm="onDelete(record)" placement="topRight" title="是否确认删除">
<a>删除</a> <a>删除</a>
</a-popconfirm> </a-popconfirm>
</Auth> </Auth>
<Auth :auth="{ sysApp: [['grantMenu'], ['grantData']] }"> <Auth :auth="{ sysRole: [['grantMenu'], ['grantData']] }">
<a-dropdown> <a-dropdown>
<a class="ant-dropdown-link"> <a class="ant-dropdown-link">
授权 授权
<a-icon type="down" /> <a-icon type="down" />
</a> </a>
<a-menu slot="overlay"> <a-menu slot="overlay">
<Auth auth="sysApp:grantMenu"> <Auth auth="sysRole:grantMenu">
<a-menu-item> <a-menu-item>
<a @click="$refs.roleMenuForm.roleMenu(record)">授权菜单</a> <a @click="$refs.roleMenuForm.roleMenu(record)">授权菜单</a>
</a-menu-item> </a-menu-item>
</Auth> </Auth>
<Auth auth="sysApp:grantData"> <Auth auth="sysRole:grantData">
<a-menu-item> <a-menu-item>
<a @click="$refs.roleOrgForm.roleOrg(record)">授权数据</a> <a @click="$refs.roleOrgForm.roleOrg(record)">授权数据</a>
</a-menu-item> </a-menu-item>
@@ -108,9 +106,7 @@ export default {
], ],
}; };
}, },
created() { created() {},
// this.onLoadCodes();
},
methods: { methods: {
/** /**
* 必要的方法 * 必要的方法
@@ -143,29 +139,6 @@ export default {
this.$refs.table.onReloadData(); this.$refs.table.onReloadData();
}, },
/**
* 加载字典数据时的必要方法
*/
// onLoadCodes() {
// this.$api
// .$queue([
// this.$api.sysDictTypeDropDownWait({ code: "yes_or_no" }),
// this.$api.sysDictTypeDropDownWait({ code: "common_status" }),
// ])
// .then(([yesOrNo, commonStatus]) => {
// this.codes.find((p) => p.code === "yes_or_no").values = yesOrNo.data;
// this.codes.find((p) => p.code === "common_status").values =
// commonStatus.data;
// });
// },
bindCodeValue(code, name) {
const c = this.codes.find((p) => p.code == name).values.find((p) => p.code == code);
if (c) {
return c.value;
}
return null;
},
/** /**
* 有编辑新增功能的必要方法 * 有编辑新增功能的必要方法
* 从列表页调用窗口的打开方法 * 从列表页调用窗口的打开方法
@@ -174,27 +147,18 @@ export default {
this.$refs[formName].onOpen(record); this.$refs[formName].onOpen(record);
}, },
onResult(success, message, successMessage) { onResult(success, successMessage) {
if (success) { if (success) {
this.$message.success(successMessage); this.$message.success(successMessage);
this.onReloadData(); this.onReloadData();
} else {
this.$refs.table.onLoaded();
this.$message.error(message);
} }
}, this.$refs.table.onLoaded();
onSetDefault(record) {
this.$refs.table.onLoading();
this.$api.sysAppSetAsDefault({ id: record.id }).then(({ success, message }) => {
this.onResult(success, message, '设置成功');
});
}, },
onDelete(record) { onDelete(record) {
this.$refs.table.onLoading(); this.$refs.table.onLoading();
this.$api.sysRoleDel(record).then(({ success, message }) => { this.$api.sysRoleDel(record).then(({ success, message }) => {
this.onResult(success, message, '删除成功'); this.onResult(success, '删除成功');
}); });
}, },
}, },

View File

@@ -59,15 +59,17 @@ export default {
this.formBody.onValidate((valid) => { this.formBody.onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysUserAdd(this.formBody.form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysUserAdd(this.formBody.form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('新增成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -46,15 +46,17 @@ export default {
this.$refs['form-body'].onValidate((valid) => { this.$refs['form-body'].onValidate((valid) => {
if (valid) { if (valid) {
this.confirmLoading = true; this.confirmLoading = true;
this.$api.sysUserEdit(this.$refs['form-body'].form).then(({ success, message }) => { this.$api
this.confirmLoading = false; .sysUserEdit(this.$refs['form-body'].form)
.then(({ success }) => {
if (success) { if (success) {
this.$message.success('编辑成功'); this.$message.success('编辑成功');
this.onCancel(); this.onCancel();
this.$emit('ok'); this.$emit('ok');
} else {
this.$message.error(message);
} }
})
.finally(() => {
this.confirmLoading = false;
}); });
} }
}); });

View File

@@ -45,11 +45,9 @@
</Auth> </Auth>
<yo-table :columns="columns" :load-data="loadData" ref="table"> <yo-table :columns="columns" :load-data="loadData" ref="table">
<div class="yo-action-bar" slot="title"> <Auth auth="sysUser:add" slot="operator">
<div class="yo-action-bar--actions">
<a-button @click="onOpen('add-form')" icon="plus">新增用户</a-button> <a-button @click="onOpen('add-form')" icon="plus">新增用户</a-button>
</div> </Auth>
</div>
<span slot="sex" slot-scope="text">{{ bindCodeValue(text, 'sex') }}</span> <span slot="sex" slot-scope="text">{{ bindCodeValue(text, 'sex') }}</span>
<span slot="status" slot-scope="text, record"> <span slot="status" slot-scope="text, record">
{{ bindCodeValue(text, 'common_status') }} {{ bindCodeValue(text, 'common_status') }}

View File

@@ -89,7 +89,10 @@ export default {
}; };
}, },
created() { mounted() {
Vue.prototype.openContentWindow = this.onOpenContentWindow;
Vue.prototype.closeContentWindow = this.onCloseContentWindow;
this.nav.loading = true; this.nav.loading = true;
this.$api.getLoginUser().then(({ data }) => { this.$api.getLoginUser().then(({ data }) => {
@@ -102,18 +105,10 @@ export default {
this.menus = data.menus; this.menus = data.menus;
this.serializeMenu(); this.serializeMenu();
this.nav.loading = false; this.nav.loading = false;
this.$root.global.defaultWindow.map((options) => {
this.onOpenContentWindow(options);
}); });
},
mounted() {
Vue.prototype.openContentWindow = this.onOpenContentWindow;
Vue.prototype.closeContentWindow = this.onCloseContentWindow;
this.onOpenContentWindow({
title: '首页',
path: '/home',
icon: 'home',
closable: false,
}); });
}, },