[Update] 更新store settings

This commit is contained in:
ibuler
2020-05-18 15:52:08 +08:00
parent 859fff7dff
commit f07e68113d
18 changed files with 159 additions and 251 deletions

View File

@@ -45,3 +45,10 @@ export function importLdapUser(data) {
data: data
})
}
export function getPublicSettings() {
return request({
url: '/api/v1/settings/public/',
method: 'get'
})
}

View File

@@ -837,18 +837,7 @@ export default {
}
},
methods: {
/**
* 手动刷新列表数据,选项的默认值为: { loading: true }
* @public
* @param {object} options 方法选项
*/
getList({ loading = true } = {}) {
const { url } = this
if (!url) {
console.warn('DataTable: url 为空, 不发送请求')
return
}
getQuery() {
// 构造query对象
let query = {}
let formValue = {}
@@ -878,7 +867,27 @@ export default {
if (this.transformQuery) {
query = this.transformQuery(query)
}
return query
},
/**
* 手动刷新列表数据,选项的默认值为: { loading: true }
* @public
* @param {object} options 方法选项
*/
getList({ loading = true } = {}) {
const { url } = this
if (!url) {
console.warn('DataTable: url 为空, 不发送请求')
return
}
const query = this.getQuery()
let formValue = {}
if (this.$refs.searchForm) {
formValue = this.$refs.searchForm.getFormValue()
Object.assign(query, formValue)
}
const queryStr =
(url.indexOf('?') > -1 ? '&' : '?') +
queryUtil.stringify(query, '=', '&')
@@ -951,7 +960,6 @@ export default {
// Orange 重置查询对象
// this.innerQuery = Object.assign(this.innerQuery, attrs)
this.innerQuery = attrs
console.log(this.innerQuery)
return this.getList()
},
/**

View File

@@ -98,6 +98,9 @@ export default {
},
search(attrs) {
return this.$refs.table.search(attrs)
},
getQuery() {
return this.$refs.table.getQuery()
}
}
}

View File

@@ -15,6 +15,7 @@
<script>
import Dialog from '@/components/Dialog'
import { createSourceIdCache } from '@/api/common'
import * as queryUtil from '@/components/DataTable/compenents/el-data-table/utils/query'
export default {
name: 'ExportDialog',
@@ -58,21 +59,29 @@ export default {
window.URL.revokeObjectURL(url)
},
async handleExport() {
let data
var resources = []
if (this.exportOption === '1') {
data = this.$parent.$parent.$refs.dataTable.$refs.dataTable.getData()
} else if (this.exportOption === '2') {
data = this.selectedRows
} else {
data = []
const url = process.env.VUE_APP_BASE_API + `${this.url}`
let query = {}
if (this.exportOption === '2') {
const resources = []
const data = this.selectedRows
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
const spm = await createSourceIdCache(resources)
query['spm'] = spm.spm
} else if (this.exportOption === '3') {
const listTableRef = this.$parent.$parent.$parent.$parent
console.log(listTableRef)
console.log(listTableRef.dataTable)
query = listTableRef.dataTable.getQuery()
delete query['limit']
delete query['offset']
}
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
const spm = await createSourceIdCache(resources)
const url = process.env.VUE_APP_BASE_API + `${this.url}?format=csv&?spm=` + spm.spm
return this.downloadCsv(url)
query['format'] = 'csv'
const queryStr =
(url.indexOf('?') > -1 ? '&' : '?') +
queryUtil.stringify(query, '=', '&')
return this.downloadCsv(url + queryStr)
},
async handleExportConfirm() {
await this.handleExport()

View File

@@ -1,52 +1,19 @@
<template>
<div>
<Dialog :title="$t('common.Export')" :visible.sync="showExportDialog" center @confirm="handleDialogConfirm('export')" @cancel="handleDialogCancel('export')">
<el-form label-position="left" style="padding-left: 50px">
<el-form-item :label="this.$t('common.imExport.ExportRange')" :label-width="'100px'">
<el-radio v-model="exportOption" class="export-item" label="1">{{ this.$t('common.imExport.ExportAll') }}</el-radio>
<br>
<el-radio v-model="exportOption" class="export-item" label="2">{{ this.$t('common.imExport.ExportOnlySelectedItems') }}</el-radio>
<br>
<el-radio v-model="exportOption" class="export-item" label="3">{{ this.$t('common.imExport.ExportOnlyFiltered') }}</el-radio>
</el-form-item>
</el-form>
</Dialog>
<Dialog :title="$t('common.Import')" :visible.sync="showImportDialog" center @confirm="handleDialogConfirm('import')" @cancel="handleDialogCancel('import')">
<el-form label-position="left" style="padding-left: 50px">
<el-form-item :label="$t('common.Import' )" :label-width="'100px'">
<el-radio v-model="importOption" class="export-item" label="1">{{ this.$t('common.Create') }}</el-radio>
<br>
<el-radio v-model="importOption" class="export-item" label="2">{{ this.$t('common.Update') }}</el-radio>
<div>
<span v-if="importOption==='1'">{{ this.$t('common.imExport.downloadImportTemplateMsg') }}<a style="color: #428bca;" :href="downloadImportTempUrl">{{ this.$t('common.Download') }}</a></span>
<span v-else>{{ this.$t('common.imExport.downloadUpdateTemplateMsg') }} <a style="color: #428bca;" @click="downloadUpdateTempUrl">{{ this.$t('common.Download') }}</a></span>
</div>
</el-form-item>
<el-form-item :label="$t('common.Upload' )" :label-width="'100px'">
<el-upload
class="upload-card"
action="string"
:http-request="upload"
list-type="text/csv"
:limit="1"
>
<el-button size="mini" type="primary">{{ this.$t('common.Upload') }}</el-button>
<div slot="tip" class="el-upload__tip">{{ this.$t('common.imExport.onlyCSVFilesTips') }}</div>
</el-upload>
</el-form-item>
</el-form>
</Dialog>
<ExportDialog :selected-rows="selectedRows" :url="url" v-bind="$attrs" v-on="$listeners" />
<ImportDialog :selected-rows="selectedRows" :url="url" v-bind="$attrs" v-on="$listeners" />
</div>
</template>
<script>
import Dialog from '@/components/Dialog'
import { createSourceIdCache } from '@/api/common'
import ExportDialog from './ExportDialog'
import ImportDialog from './ImportDialog'
export default {
name: 'DialogAction',
components: {
Dialog
ExportDialog,
ImportDialog
},
props: {
selectedRows: {
@@ -60,108 +27,6 @@ export default {
},
data() {
return {
showExportDialog: false,
showImportDialog: false,
importOption: '1',
exportOption: '1',
meta: {}
}
},
computed: {
hasSelected() {
return this.selectedRows.length > 0
},
importTitle() {
if (this.importOption === '1') {
return this.$t('common.Import')
} else {
return this.$t('common.Update')
}
},
upLoadUrl() {
return this.url
},
downloadImportTempUrl() {
return process.env.VUE_APP_BASE_API + this.url + '?format=csv&template=import&limit=1'
}
},
mounted() {
this.$eventBus.$on('showExportDialog', (row) => {
this.showExportDialog = true
})
this.$eventBus.$on('showImportDialog', (row) => {
this.showImportDialog = true
})
},
methods: {
upload(item) {
this.$axios.put(
this.upLoadUrl,
item.file
).then((res) => {
console.log('')
})
},
downloadCsv(url) {
const a = document.createElement('a')
a.href = url
a.click()
window.URL.revokeObjectURL(url)
},
async handleExport() {
let data
var resources = []
if (this.exportOption === '1') {
data = this.$parent.$parent.$refs.dataTable.$refs.dataTable.getData()
} else if (this.exportOption === '2') {
data = this.selectedRows
} else {
data = []
}
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
const spm = await createSourceIdCache(resources)
const url = process.env.VUE_APP_BASE_API + `${this.url}?format=csv&?spm=` + spm.spm
return this.downloadCsv(url)
},
handleImport() {
},
async downloadUpdateTempUrl() {
var resources = []
const data = this.$parent.$parent.$refs.dataTable.$refs.dataTable.getData()
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
const spm = await createSourceIdCache(resources)
const url = process.env.VUE_APP_BASE_API + `${this.url}?format=csv&template=update&spm=` + spm.spm
return this.downloadCsv(url)
},
async handleDialogConfirm(val) {
switch (val) {
case 'export':
await this.handleExport()
this.showExportDialog = false
break
case 'import':
await this.handleImport()
this.showImportDialog = false
break
default:
break
}
},
handleDialogCancel(val) {
switch (val) {
case 'export':
this.showExportDialog = false
break
case 'import':
this.showImportDialog = false
break
default:
break
}
}
}
}

View File

@@ -1,24 +1,29 @@
<template>
<Dialog :title="$t('common.Import')" :visible.sync="showImportDialog" center @confirm="handleDialogConfirm('import')" @cancel="handleDialogCancel('import')">
<Dialog :title="$t('common.Import')" :visible.sync="showImportDialog" center @confirm="handleImportConfirm()" @cancel="handleImportCancel('import')">
<el-form label-position="left" style="padding-left: 50px">
<el-form-item :label="$t('common.Import' )" :label-width="'100px'">
<el-radio v-model="importOption" class="export-item" label="1">{{ this.$t('common.Create') }}</el-radio>
<br>
<el-radio v-model="importOption" class="export-item" label="2">{{ this.$t('common.Update') }}</el-radio>
<div>
<span v-if="importOption==='1'">{{ this.$t('common.imExport.downloadImportTemplateMsg') }}<a style="color: #428bca;" :href="downloadImportTempUrl">{{ this.$t('common.Download') }}</a></span>
<span v-else>{{ this.$t('common.imExport.downloadUpdateTemplateMsg') }} <a style="color: #428bca;" @click="downloadUpdateTempUrl">{{ this.$t('common.Download') }}</a></span>
<span v-if="importOption==='1'" class="el-upload__tip">
{{ this.$t('common.imExport.downloadImportTemplateMsg') }}
<el-link type="success" :underline="false" :href="downloadImportTempUrl">{{ this.$t('common.Download') }}</el-link>
</span>
<span v-else class="el-upload__tip">
{{ this.$t('common.imExport.downloadUpdateTemplateMsg') }}
<el-link type="success" :underline="false" @click="downloadUpdateTempUrl">{{ this.$t('common.Download') }}</el-link>
</span>
</div>
</el-form-item>
<el-form-item :label="$t('common.Upload' )" :label-width="'100px'">
<el-upload
class="upload-card"
ref="upload"
action="string"
:http-request="upload"
:http-request="handleImport"
list-type="text/csv"
:limit="1"
>
<el-button size="mini" type="primary">{{ this.$t('common.Upload') }}</el-button>
<el-button size="mini" type="default">{{ this.$t('common.SelectFile') }}</el-button>
<div slot="tip" class="el-upload__tip">{{ this.$t('common.imExport.onlyCSVFilesTips') }}</div>
</el-upload>
</el-form-item>
@@ -48,22 +53,13 @@ export default {
data() {
return {
showImportDialog: false,
importOption: '1',
exportOption: '1',
meta: {}
importOption: '1'
}
},
computed: {
hasSelected() {
return this.selectedRows.length > 0
},
importTitle() {
if (this.importOption === '1') {
return this.$t('common.Import')
} else {
return this.$t('common.Update')
}
},
upLoadUrl() {
return this.url
},
@@ -72,20 +68,29 @@ export default {
}
},
mounted() {
this.$eventBus.$on('showExportDialog', (row) => {
this.showExportDialog = true
})
this.$eventBus.$on('showImportDialog', (row) => {
this.showImportDialog = true
})
},
methods: {
upload(item) {
performUpdate(item) {
this.$axios.put(
this.upLoadUrl,
item.file
).then((res) => {
console.log('')
item.file,
{ headers: { 'Content-Type': 'text/csv' }}
).then((data) => {
const msg = this.$t('common.imExport.updateSuccessMsg', { count: data.length })
this.$message.success(msg)
})
},
performCreate(item) {
this.$axios.post(
this.upLoadUrl,
item.file,
{ headers: { 'Content-Type': 'text/csv' }}
).then((data) => {
const msg = this.$t('common.imExport.createSuccessMsg', { count: data.length })
this.$message.success(msg)
})
},
downloadCsv(url) {
@@ -94,28 +99,16 @@ export default {
a.click()
window.URL.revokeObjectURL(url)
},
async handleExport() {
let data
var resources = []
if (this.exportOption === '1') {
data = this.$parent.$parent.$refs.dataTable.$refs.dataTable.getData()
} else if (this.exportOption === '2') {
data = this.selectedRows
handleImport(item) {
if (this.importOption === '1') {
this.performCreate(item)
} else {
data = []
this.performUpdate(item)
}
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
const spm = await createSourceIdCache(resources)
const url = process.env.VUE_APP_BASE_API + `${this.url}?format=csv&?spm=` + spm.spm
return this.downloadCsv(url)
},
handleImport() {
},
async downloadUpdateTempUrl() {
var resources = []
const data = this.$parent.$parent.$refs.dataTable.$refs.dataTable.getData()
const data = this.selectedRows
for (let index = 0; index < data.length; index++) {
resources.push(data[index].id)
}
@@ -123,31 +116,11 @@ export default {
const url = process.env.VUE_APP_BASE_API + `${this.url}?format=csv&template=update&spm=` + spm.spm
return this.downloadCsv(url)
},
async handleDialogConfirm(val) {
switch (val) {
case 'export':
await this.handleExport()
this.showExportDialog = false
break
case 'import':
await this.handleImport()
this.showImportDialog = false
break
default:
break
}
async handleImportConfirm() {
this.$refs.upload.submit()
},
handleDialogCancel(val) {
switch (val) {
case 'export':
this.showExportDialog = false
break
case 'import':
this.showImportDialog = false
break
default:
break
}
handleImportCancel() {
this.showImportDialog = false
}
}
}

View File

@@ -31,6 +31,10 @@ export default {
type: Array,
default: () => []
},
reloadTable: {
type: Function,
default: () => {}
},
extraRightSideActions: {
type: Array,
default: () => []

View File

@@ -38,19 +38,24 @@ export default {
selectedRows: []
}
},
computed: {
dataTable() {
return this.$refs.dataTable.$refs.dataTable
}
},
methods: {
handleSelectionChange(val) {
this.selectedRows = val
var obj = {}
const obj = {}
val.forEach((item, index) => { obj[index] = item })
// 已知Bug必须避免数组扁平化
this.dispatch('AssetSelect', 'SelectionChange', obj)
},
reloadTable() {
this.$refs.dataTable.$refs.dataTable.getList()
this.dataTable.getList()
},
search(attrs) {
return this.$refs.dataTable.$refs.dataTable.search(attrs)
return this.dataTable.search(attrs)
}
}
}

View File

@@ -73,7 +73,7 @@ export default {
this.filterKey = keys[0]
this.$refs.Cascade.clearCheckedNodes()
}
console.log(this.filterKey)
this.$log.debug(this.filterKey)
},
handleTagClose(evt) {
this.$delete(this.filterTags, evt)

View File

@@ -97,6 +97,8 @@
"name": "名称",
"action": "动作",
"Active": "激活中",
"Basic": "基本",
"SelectFile": "选择文件",
"nav": {
"Docs": "文档",
"Help": "帮助",
@@ -113,7 +115,9 @@
"ExportRange": "导出范围",
"downloadImportTemplateMsg": "下载导入模板",
"downloadUpdateTemplateMsg": "下载更新模板",
"onlyCSVFilesTips": "仅支持csv文件导入"
"onlyCSVFilesTips": "仅支持csv文件导入",
"updateSuccessMsg": "导入更新成功,总共:{count}",
"createSuccessMsg": "导入创建成功,总共:{count}"
},
"Download": "下载",
"Upload": "上传",
@@ -374,7 +378,8 @@
},
"auth": {
"authExpireMsg": "账号已退出,请重新登录",
"Re-Login": "重新登录",
"ReLogin": "重新登录",
"LoginRequiredMsg": "账号已退出,请重新登录",
"You have been logged out, Please log in again": ""
},
"jobcenter": {

View File

@@ -733,8 +733,8 @@
"Delete failed": "",
"添加筛选条件": "",
"auth": {
"You have been logged out, Please log in again": "",
"Re-Login": ""
"LoginRequireMsg": "You have been logged out, Please log in again",
"ReLogin": "Re-Login"
},
"名称": "",
"用户名": "",
@@ -844,4 +844,4 @@
"Close": "",
"Comment": ""
}
}
}

View File

@@ -30,6 +30,7 @@ export default {
'currentUser'
])
}
}
</script>

View File

@@ -41,6 +41,12 @@ router.beforeEach(async(to, from, next) => {
NProgress.done()
return
}
// 获取Public settings
const publicSettings = store.getters.publicSettings
if (!publicSettings) {
await store.dispatch('settings/getPublicSettings')
}
// determine whether the user has obtained his permission roles through getProfile
const currentUser = store.getters.currentUser
const hasRoles = currentUser && currentUser.current_org_roles && currentUser.current_org_roles.length > 0

View File

@@ -7,6 +7,7 @@ const getters = {
currentUser: state => state.users.profile,
permission_routes: state => state.permission.routes,
visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews
cachedViews: state => state.tagsView.cachedViews,
publicSettings: state => state.settings.publicSettings
}
export default getters

View File

@@ -1,4 +1,5 @@
import defaultSettings from '@/settings'
import { getPublicSettings } from '@/api/settings'
const { showSettings, fixedHeader, sidebarLogo, tagsView } = defaultSettings
@@ -6,7 +7,8 @@ const state = {
showSettings: showSettings,
fixedHeader: fixedHeader,
sidebarLogo: sidebarLogo,
tagsView: tagsView
tagsView: tagsView,
publicSettings: null
}
const mutations = {
@@ -14,12 +16,26 @@ const mutations = {
if (state.hasOwnProperty(key)) {
state[key] = value
}
},
SET_PUBLIC_SETTINGS: (state, settings) => {
state.publicSettings = settings
}
}
const actions = {
changeSetting({ commit }, data) {
commit('CHANGE_SETTING', data)
},
// get user Profile
getPublicSettings({ commit, state }) {
return new Promise((resolve, reject) => {
getPublicSettings().then(response => {
commit('SET_PUBLIC_SETTINGS', response.data)
resolve(response)
}).catch(error => {
reject(error)
})
})
}
}

View File

@@ -379,3 +379,8 @@ td .el-button.el-button--mini {
.el-table__header thead tr th {
border-bottom: 1.5px solid #e7e7e7 !important;
}
.el-table .cell, .el-table--border td:first-child .cell, .el-table--border th:first-child .cell {
padding-left: 10px;
padding-right: 14px;
}

View File

@@ -66,9 +66,9 @@ service.interceptors.response.use(
const response = error.response
if (response.status === 401) {
const title = ''
const msg = i18n.t('auth.You have been logged out, Please log in again')
const msg = i18n.t('auth.LoginRequiredMsg')
MessageBox.confirm(msg, title, {
confirmButtonText: i18n.t('auth.Re-Login'),
confirmButtonText: i18n.t('auth.ReLogin'),
cancelButtonText: i18n.t('common.Cancel'),
type: 'warning'
}).then(() => {

View File

@@ -14,15 +14,15 @@ export default {
initial: {
},
url: '/api/v1/users/groups/',
fields: ['name', 'users', 'comment'],
fields: [
[this.$t('common.Basic'), ['name', 'users', 'comment']]
],
fieldsMeta: {
users: {
el: {
value: [],
url: '/api/v1/users/users/',
helpMessage: 'hello'
},
helpText: '请输入用户 <a href="">更多</a>'
url: '/api/v1/users/users/'
}
}
}
}