Merge pull request #129 from veops/dev_ui

前端更新
This commit is contained in:
pycook 2023-07-25 18:19:47 +08:00 committed by GitHub
commit b787bd9b7b
6 changed files with 195 additions and 126 deletions

View File

@ -1,6 +1,14 @@
<template> <template>
<div class="ci-type-grant"> <div class="ci-type-grant">
<vxe-table size="mini" stripe class="ops-stripe-table" :data="filterTableData" :max-height="`${tableHeight}px`"> <vxe-table
ref="xTable"
size="mini"
stripe
class="ops-stripe-table"
:data="filterTableData"
:max-height="`${tableHeight}px`"
:row-style="(params) => getCurrentRowStyle(params, addedRids)"
>
<vxe-column field="name"></vxe-column> <vxe-column field="name"></vxe-column>
<vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]"> <vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]">
<template #default="{row}"> <template #default="{row}">
@ -37,6 +45,7 @@ import _ from 'lodash'
import { permMap } from './constants.js' import { permMap } from './constants.js'
import { grantCiType, revokeCiType } from '../../api/CIType' import { grantCiType, revokeCiType } from '../../api/CIType'
import ReadCheckbox from './readCheckbox.vue' import ReadCheckbox from './readCheckbox.vue'
import { getCurrentRowStyle } from './utils'
export default { export default {
name: 'CiTypeGrant', name: 'CiTypeGrant',
@ -55,10 +64,13 @@ export default {
type: String, type: String,
default: 'ci_type', default: 'ci_type',
}, },
addedRids: {
type: Array,
default: () => [],
},
}, },
computed: { computed: {
filterTableData() { filterTableData() {
console.log(_.cloneDeep(this.tableData))
const _tableData = this.tableData.filter((data) => { const _tableData = this.tableData.filter((data) => {
const _intersection = _.intersection( const _intersection = _.intersection(
Object.keys(data), Object.keys(data),
@ -90,6 +102,7 @@ export default {
} }
}, },
methods: { methods: {
getCurrentRowStyle,
async handleChange(e, col, row) { async handleChange(e, col, row) {
if (e.target.checked) { if (e.target.checked) {
await grantCiType(this.CITypeId, row.rid, { perms: [col] }).catch(() => { await grantCiType(this.CITypeId, row.rid, { perms: [col] }).catch(() => {

View File

@ -9,6 +9,8 @@
@grantDepart="grantDepart" @grantDepart="grantDepart"
@grantRole="grantRole" @grantRole="grantRole"
@getTableData="getTableData" @getTableData="getTableData"
ref="grant_ci_type"
:addedRids="addedRids"
/> />
</template> </template>
<template <template
@ -25,6 +27,8 @@
@grantRole="grantRole" @grantRole="grantRole"
@getTableData="getTableData" @getTableData="getTableData"
@openReadGrantModal="openReadGrantModal" @openReadGrantModal="openReadGrantModal"
ref="grant_ci"
:addedRids="addedRids"
/> />
</template> </template>
<template v-if="cmdbGrantType.includes('type_relation')"> <template v-if="cmdbGrantType.includes('type_relation')">
@ -36,6 +40,8 @@
@grantDepart="grantDepart" @grantDepart="grantDepart"
@grantRole="grantRole" @grantRole="grantRole"
@getTableData="getTableData" @getTableData="getTableData"
ref="grant_type_relation"
:addedRids="addedRids"
/> />
</template> </template>
<template v-if="cmdbGrantType.includes('relation_view')"> <template v-if="cmdbGrantType.includes('relation_view')">
@ -47,6 +53,8 @@
@grantDepart="grantDepart" @grantDepart="grantDepart"
@grantRole="grantRole" @grantRole="grantRole"
@getTableData="getTableData" @getTableData="getTableData"
ref="grant_relation_view"
:addedRids="addedRids"
/> />
</template> </template>
@ -108,6 +116,7 @@ export default {
attrGroup: [], attrGroup: [],
filerPerimissions: {}, filerPerimissions: {},
loading: false, loading: false,
addedRids: [], // rid
} }
}, },
computed: { computed: {
@ -282,6 +291,12 @@ export default {
}) })
) )
} }
this.addedRids = rids
this.$nextTick(() => {
setTimeout(() => {
this.$refs[`grant_${grantType}`].$refs.xTable.elemStore['main-body-wrapper'].scrollTo(0, 0)
}, 300)
})
}, },
openReadGrantModal(col, row) { openReadGrantModal(col, row) {
this.$refs.readGrantModal.open(col, row) this.$refs.readGrantModal.open(col, row)

View File

@ -1,6 +1,14 @@
<template> <template>
<div class="ci-relation-grant"> <div class="ci-relation-grant">
<vxe-table size="mini" stripe class="ops-stripe-table" :data="tableData" :max-height="`${tableHeight}px`"> <vxe-table
ref="xTable"
size="mini"
stripe
class="ops-stripe-table"
:data="tableData"
:max-height="`${tableHeight}px`"
:row-style="(params) => getCurrentRowStyle(params, addedRids)"
>
<vxe-column field="name"></vxe-column> <vxe-column field="name"></vxe-column>
<vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]"> <vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]">
<template #default="{row}"> <template #default="{row}">
@ -18,6 +26,8 @@
<script> <script>
import { permMap } from './constants.js' import { permMap } from './constants.js'
import { grantRelationView, revokeRelationView } from '../../api/preference.js' import { grantRelationView, revokeRelationView } from '../../api/preference.js'
import { getCurrentRowStyle } from './utils'
export default { export default {
name: 'RelationViewGrant', name: 'RelationViewGrant',
inject: ['loading', 'isModal'], inject: ['loading', 'isModal'],
@ -34,6 +44,10 @@ export default {
type: String, type: String,
default: 'relation_view', default: 'relation_view',
}, },
addedRids: {
type: Array,
default: () => [],
},
}, },
data() { data() {
return { return {
@ -53,6 +67,7 @@ export default {
}, },
}, },
methods: { methods: {
getCurrentRowStyle,
grantDepart() { grantDepart() {
this.$emit('grantDepart', this.grantType) this.$emit('grantDepart', this.grantType)
}, },

View File

@ -1,6 +1,14 @@
<template> <template>
<div class="ci-relation-grant"> <div class="ci-relation-grant">
<vxe-table size="mini" stripe class="ops-stripe-table" :data="tableData" :max-height="`${tableHeight}px`"> <vxe-table
ref="xTable"
size="mini"
stripe
class="ops-stripe-table"
:data="tableData"
:max-height="`${tableHeight}px`"
:row-style="(params) => getCurrentRowStyle(params, addedRids)"
>
<vxe-column field="name"></vxe-column> <vxe-column field="name"></vxe-column>
<vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]"> <vxe-column v-for="col in columns" :key="col" :field="col" :title="permMap[col]">
<template #default="{row}"> <template #default="{row}">
@ -18,6 +26,8 @@
<script> <script>
import { permMap } from './constants.js' import { permMap } from './constants.js'
import { grantTypeRelation, revokeTypeRelation } from '../../api/CITypeRelation.js' import { grantTypeRelation, revokeTypeRelation } from '../../api/CITypeRelation.js'
import { getCurrentRowStyle } from './utils'
export default { export default {
name: 'TypeRelationGrant', name: 'TypeRelationGrant',
inject: ['loading', 'isModal'], inject: ['loading', 'isModal'],
@ -34,6 +44,10 @@ export default {
type: Array, type: Array,
default: null, default: null,
}, },
addedRids: {
type: Array,
default: () => [],
},
}, },
data() { data() {
return { return {
@ -53,6 +67,7 @@ export default {
}, },
}, },
methods: { methods: {
getCurrentRowStyle,
grantDepart() { grantDepart() {
this.$emit('grantDepart', this.grantType) this.$emit('grantDepart', this.grantType)
}, },

View File

@ -0,0 +1,4 @@
export const getCurrentRowStyle = ({ row }, addedRids) => {
const idx = addedRids.findIndex(item => item.rid === row.rid)
return idx > -1 ? 'background-color:#E0E7FF!important' : ''
}

View File

@ -1,130 +1,137 @@
<template> <template>
<a-form :form="form" class="create-new-attribute"> <a-form :form="form" class="create-new-attribute">
<a-divider style="font-size:14px;margin-top:6px;">基础设置</a-divider> <a-divider style="font-size:14px;margin-top:6px;">基础设置</a-divider>
<a-col :span="12"> <a-row>
<a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="属性名(英文)"> <a-col :span="12">
<a-input <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="属性名(英文)">
name="name"
placeholder="英文"
v-decorator="[
'name',
{
rules: [
{ required: true, message: '请输入属性名' },
{ message: '不能以数字开头,可以是英文 数字以及下划线 (_)', pattern: RegExp('^(?!\\d)[a-zA-Z_0-9]+$') },
{ message: '内置字段', pattern: RegExp('^(?!(id|_id|ci_id|type|_type|ci_type)$).*$') },
],
},
]"
/>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="别名">
<a-input name="alias" v-decorator="['alias', { rules: [] }]" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="数据类型">
<a-select
name="value_type"
style="width: 100%"
v-decorator="['value_type', { rules: [{ required: true }], initialValue: '2' }]"
@change="handleChangeValueType"
>
<a-select-option :value="key" :key="key" v-for="(value, key) in valueTypeMap">{{ value }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="currentValueType === '6' ? 24 : 12">
<a-form-item
:label-col="{ span: currentValueType === '6' ? 4 : 8 }"
:wrapper-col="{ span: currentValueType === '6' ? 18 : 12 }"
label="默认值"
>
<template>
<a-select
v-if="form.getFieldValue('is_list')"
mode="tags"
:style="{ width: '100%' }"
v-decorator="['default_value', { rules: [{ required: false }] }]"
>
</a-select>
<a-input-number
style="width: 100%"
v-else-if="currentValueType === '1'"
v-decorator="['default_value', { rules: [{ required: false }] }]"
>
</a-input-number>
<a-select
v-decorator="['default_value', { rules: [{ required: false }] }]"
mode="tags"
v-else-if="currentValueType === '0'"
@select="selectIntDefaultValue"
>
<a-select-option key="$auto_inc_id">
自增ID
</a-select-option>
</a-select>
<a-input <a-input
style="width: 100%" name="name"
v-else-if="currentValueType === '2' || currentValueType === '5'" placeholder="英文"
v-decorator="['default_value', { rules: [{ required: false }] }]" v-decorator="[
> 'name',
</a-input> {
<a-select rules: [
allowClear { required: true, message: '请输入属性名' },
v-decorator="['default_value', { rules: [{ required: false }] }]" {
v-else-if="currentValueType === '3' && defaultForDatetime !== '$custom_time'" message: '不能以数字开头,可以是英文 数字以及下划线 (_)',
@select="changeDefaultForDatetime" pattern: RegExp('^(?!\\d)[a-zA-Z_0-9]+$'),
> },
<a-select-option key="$created_at"> { message: '内置字段', pattern: RegExp('^(?!(id|_id|ci_id|type|_type|ci_type)$).*$') },
创建时间 ],
</a-select-option> },
<a-select-option key="$updated_at"> ]"
更新时间
</a-select-option>
<a-select-option key="$custom_time">
自定义时间
</a-select-option>
</a-select>
<template v-else-if="currentValueType === '4' || currentValueType === '3'">
<a-date-picker
style="width: 100%"
v-decorator="['default_value', { rules: [{ required: false }] }]"
:format="currentValueType === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
:showTime="currentValueType === '4' ? false : { format: 'HH:mm:ss' }"
/>
<a-dropdown
:style="{ position: 'absolute', right: '-15px', top: '-10px' }"
:trigger="['click']"
v-if="currentValueType === '3'"
>
<a><a-icon type="down" /> </a>
<a-menu slot="overlay" @click="onClick">
<a-menu-item key="$created_at">
<a>创建时间</a>
</a-menu-item>
<a-menu-item key="$updated_at">
<a>更新时间</a>
</a-menu-item>
</a-menu>
</a-dropdown>
</template>
<vue-json-editor
v-else-if="currentValueType === '6'"
:style="{ '--custom-height': `${200}px` }"
v-model="default_value_json"
:showBtns="false"
:mode="'code'"
lang="zh"
@json-change="onJsonChange"
@has-error="onJsonError"
/> />
</template> </a-form-item>
</a-form-item> </a-col>
</a-col> <a-col :span="12">
<a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="别名">
<a-input name="alias" v-decorator="['alias', { rules: [] }]" />
</a-form-item>
</a-col>
</a-row>
<a-row>
<a-col :span="12">
<a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="数据类型">
<a-select
name="value_type"
style="width: 100%"
v-decorator="['value_type', { rules: [{ required: true }], initialValue: '2' }]"
@change="handleChangeValueType"
>
<a-select-option :value="key" :key="key" v-for="(value, key) in valueTypeMap">{{ value }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="currentValueType === '6' ? 24 : 12">
<a-form-item
:label-col="{ span: currentValueType === '6' ? 4 : 8 }"
:wrapper-col="{ span: currentValueType === '6' ? 18 : 12 }"
label="默认值"
>
<template>
<a-select
v-if="form.getFieldValue('is_list')"
mode="tags"
:style="{ width: '100%' }"
v-decorator="['default_value', { rules: [{ required: false }] }]"
>
</a-select>
<a-input-number
style="width: 100%"
v-else-if="currentValueType === '1'"
v-decorator="['default_value', { rules: [{ required: false }] }]"
>
</a-input-number>
<a-select
v-decorator="['default_value', { rules: [{ required: false }] }]"
mode="tags"
v-else-if="currentValueType === '0'"
@select="selectIntDefaultValue"
>
<a-select-option key="$auto_inc_id">
自增ID
</a-select-option>
</a-select>
<a-input
style="width: 100%"
v-else-if="currentValueType === '2' || currentValueType === '5'"
v-decorator="['default_value', { rules: [{ required: false }] }]"
>
</a-input>
<a-select
allowClear
v-decorator="['default_value', { rules: [{ required: false }] }]"
v-else-if="currentValueType === '3' && defaultForDatetime !== '$custom_time'"
@select="changeDefaultForDatetime"
>
<a-select-option key="$created_at">
创建时间
</a-select-option>
<a-select-option key="$updated_at">
更新时间
</a-select-option>
<a-select-option key="$custom_time">
自定义时间
</a-select-option>
</a-select>
<template v-else-if="currentValueType === '4' || currentValueType === '3'">
<a-date-picker
style="width: 100%"
v-decorator="['default_value', { rules: [{ required: false }] }]"
:format="currentValueType === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
:showTime="currentValueType === '4' ? false : { format: 'HH:mm:ss' }"
/>
<a-dropdown
:style="{ position: 'absolute', right: '-15px', top: '-10px' }"
:trigger="['click']"
v-if="currentValueType === '3'"
>
<a><a-icon type="down" /> </a>
<a-menu slot="overlay" @click="onClick">
<a-menu-item key="$created_at">
<a>创建时间</a>
</a-menu-item>
<a-menu-item key="$updated_at">
<a>更新时间</a>
</a-menu-item>
</a-menu>
</a-dropdown>
</template>
<vue-json-editor
v-else-if="currentValueType === '6'"
:style="{ '--custom-height': `${200}px` }"
v-model="default_value_json"
:showBtns="false"
:mode="'code'"
lang="zh"
@json-change="onJsonChange"
@has-error="onJsonError"
/>
</template>
</a-form-item>
</a-col>
</a-row>
<a-col :span="6"> <a-col :span="6">
<a-form-item <a-form-item