master
xy 3 years ago
parent 27127f0ef5
commit 74a509c812

@ -1,31 +1,32 @@
import request from '@/utils/request'
export function save(data) {
return request({
url: '/api/admin/department/save',
method: 'post',
data
})
}
export function listdept() {
return request({
url: '/api/admin/department',
method: 'get'
})
}
export function listdeptNoAuth() {
return request({
url: '/api/admin/other/admin-department-list',
method: 'get'
})
}
export function del(data) {
return request({
url: '/api/admin/department/delete',
method: 'post',
data
})
}
import request from '@/utils/request'
export function save(data) {
return request({
url: '/api/admin/department/save',
method: 'post',
data
})
}
export function listdept() {
return request({
url: '/api/admin/department',
method: 'get'
})
}
export function listdeptNoAuth(params) {
return request({
url: '/api/admin/other/admin-department-list',
method: 'get',
params
})
}
export function del(data) {
return request({
url: '/api/admin/department/delete',
method: 'post',
data
})
}

@ -15,7 +15,8 @@ export const addPropsMap = new Map([
}],
["date", {
clearable: true,
valueFormat: 'yyyy-MM-dd'
valueFormat: 'yyyy-MM-dd',
defaultValue: new Date()
}],
["datetime", {
type: 'datetime',

@ -10,7 +10,8 @@ const state = {
jianshu: '',
leixing: '',
sort_name: '',
sort_type: "desc"
sort_type: "desc",
zhuangtai: 4
},
materials: {
total: 0,
@ -39,6 +40,10 @@ const mutations = {
state[key] = 'desc'
continue
}
if (key === 'zhuangtai') {
state[key] = 4
continue
}
state.select[key] = ''
}
}

@ -1,136 +1,142 @@
import {
login,
logout,
getInfo
} from '@/api/user'
import {
getToken,
setToken,
removeToken
} from '@/utils/auth'
import {
resetRouter
} from '@/router'
const getDefaultState = () => {
return {
token: getToken(),
name: '',
avatar: '',
roles: []
}
}
const state = getDefaultState()
const mutations = {
RESET_STATE: (state) => {
Object.assign(state, getDefaultState())
},
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
},
SET_ROLES: (state, roles) => {
state.roles = roles
}
}
const actions = {
// user login
login({
commit
}, userInfo) {
const {
username,
password
} = userInfo
return new Promise((resolve, reject) => {
login({
username: username.trim(),
password: password
}).then(response => {
console.log(response)
const {
data
} = response;
console.log(response.access_token)
commit('SET_TOKEN', response.access_token)
setToken(response.access_token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// get user info
getInfo({
commit,
state
}) {
return new Promise((resolve, reject) => {
getInfo(state.token).then(response => {
if (!response) {
reject('身份验证失败请重新登录')
}
response["roles"] = ["admin"];
const {
roles,
name,
avatar
} = response
commit('SET_ROLES', roles)
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
// user logout
logout({
commit,
state
}) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
removeToken() // must remove token first
resetRouter()
commit('RESET_STATE')
resolve()
}).catch(error => {
reject(error)
})
})
},
// remove token
resetToken({
commit
}) {
return new Promise(resolve => {
removeToken() // must remove token first
commit('RESET_STATE')
resolve()
})
}
}
export default {
namespaced: true,
state,
mutations,
actions
import {
login,
logout,
getInfo
} from '@/api/user'
import {
getToken,
setToken,
removeToken
} from '@/utils/auth'
import {
resetRouter
} from '@/router'
const getDefaultState = () => {
return {
token: getToken(),
name: '',
avatar: '',
roles: [],
department: {}
}
}
const state = getDefaultState()
const mutations = {
RESET_STATE: (state) => {
Object.assign(state, getDefaultState())
},
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
},
SET_ROLES: (state, roles) => {
state.roles = roles
},
SET_DEPARTMENT:(state, department) => {
state.department = department
}
}
const actions = {
// user login
login({
commit
}, userInfo) {
const {
username,
password
} = userInfo
return new Promise((resolve, reject) => {
login({
username: username.trim(),
password: password
}).then(response => {
console.log(response)
const {
data
} = response;
console.log(response.access_token)
commit('SET_TOKEN', response.access_token)
setToken(response.access_token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// get user info
getInfo({
commit,
state
}) {
return new Promise((resolve, reject) => {
getInfo(state.token).then(response => {
if (!response) {
reject('身份验证失败请重新登录')
}
response["roles"] = ["admin"];
const {
roles,
name,
avatar,
department
} = response
commit('SET_ROLES', roles)
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
commit('SET_DEPARTMENT', department)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
// user logout
logout({
commit,
state
}) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
removeToken() // must remove token first
resetRouter()
commit('RESET_STATE')
resolve()
}).catch(error => {
reject(error)
})
})
},
// remove token
resetToken({
commit
}) {
return new Promise(resolve => {
removeToken() // must remove token first
commit('RESET_STATE')
resolve()
})
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

@ -3,7 +3,7 @@ import { save, show, index, destroy } from "@/api/system/baseForm";
import { getparameter } from "@/api/system/dictionary";
import { domMap } from "@/const/inputType";
import { addPropsMap } from "@/const/addProps";
import {deepCopy} from "@/utils";
import { deepCopy } from "@/utils";
export default {
props: {
formInfo: {
@ -17,7 +17,7 @@ export default {
"el-dialog",
{
props: {
top: '8vh',
top: "8vh",
title: "新增",
visible: this.dialogVisible,
width: "750px",
@ -29,136 +29,165 @@ export default {
},
},
[
h('el-scrollbar', {
style: {
'height': '58vh'
}
}, [h(
"el-form",
h(
"el-scrollbar",
{
ref: "elForm",
style: {
'padding-right': '12px'
},
props: {
model: this.form,
labelWidth: "80px",
rules: this.rules,
labelPosition: "right",
size: "small"
height: "58vh",
},
},
(() => {
let dom = [];
this.formInfo.filter(i => i.form_show).forEach((i, index) => {
dom.push(
h(
"el-form-item",
{
ref: `elFormItem${i.field}`,
style: {
width: "100%",
},
props: {
label: i.name,
prop: i.field,
required:
i.validation instanceof Array
? !!i.validation.find((i) => i === "required")
: false,
},
},
this.$scopedSlots[i.field]
? this.$scopedSlots[i.field]({ fieldInfo: i, form: this.form, file: this.file })
: [
h(
domMap.get(i.edit_input),
{
ref: `elEdit_${i.field}`,
style: {
width: "100%",
},
props: {
...addPropsMap.get(i.edit_input),
...this.extraProps(i),
placeholder: i.help,
value: this.form[i.field],
},
attrs: {
placeholder: i.help || `请填写${i.name}`,
},
on: {
[this.getEventType(i.edit_input)]: (e) => {
if (i.field) {
this.form[i.field] = e;
this.form = Object.assign({}, this.form);
}
[
h(
"el-form",
{
ref: "elForm",
style: {
"padding-right": "12px",
},
props: {
model: this.form,
labelWidth: "80px",
rules: this.rules,
labelPosition: "right",
size: "small",
},
},
(() => {
let dom = [];
this.formInfo
.filter((i) => i.form_show)
.forEach((i, index) => {
if (
!/\/manage\/rule/.test(this.$route.fullPath) &&
!!["nianfen", "bianhao", "wenjian"].find(
(j) => j === i.field
)
) {
} else {
dom.push(
h(
"el-form-item",
{
ref: `elFormItem${i.field}`,
style: {
width: "100%",
},
props: {
label: i.name,
prop: i.field,
required:
i.validation instanceof Array
? !!i.validation.find((i) => i === "required")
: false,
},
},
scopedSlots:
i.edit_input === "file" ||
i.edit_input === "files"
? {
file: (scope) => {
let { file } = scope;
return [
h("div", {}, [
h("i", {
class: {
"el-icon-circle-check":
file.status === "success",
"el-icon-loading":
file.status === "uploading",
},
style: {
color:
file.status === "success"
? "green"
: "",
},
}),
h(
"a",
{
attrs: {
href: file.url,
download: file.name,
},
class: {
"uploaded-a":
file.status === "success",
},
style: {
'padding': '0 4px'
},
},
file.name
),
]),
h("i", {
class: "el-icon-close",
on: {
["click"]: () =>
this.fileRemoveHandler(
file,
i.field
),
this.$scopedSlots[i.field]
? this.$scopedSlots[i.field]({
fieldInfo: i,
form: this.form,
file: this.file,
})
: [
h(
domMap.get(i.edit_input),
{
ref: `elEdit_${i.field}`,
style: {
width: "100%",
},
props: {
...addPropsMap.get(i.edit_input),
...this.extraProps(i),
placeholder: i.help,
value: this.form[i.field],
},
attrs: {
placeholder: i.help || `请填写${i.name}`,
},
on: {
[this.getEventType(i.edit_input)]: (
e
) => {
if (i.field) {
this.form[i.field] = e;
this.form = Object.assign(
{},
this.form
);
}
},
}),
];
},
}
: "",
},
this.optionsRender(h, i)
),
]
)
);
});
return dom;
})()
)]),
},
scopedSlots:
i.edit_input === "file" ||
i.edit_input === "files"
? {
file: (scope) => {
let { file } = scope;
return [
h("div", {}, [
h("i", {
class: {
"el-icon-circle-check":
file.status ===
"success",
"el-icon-loading":
file.status ===
"uploading",
},
style: {
color:
file.status ===
"success"
? "green"
: "",
},
}),
h(
"a",
{
attrs: {
href: file.url,
download: file.name,
},
class: {
"uploaded-a":
file.status ===
"success",
},
style: {
padding: "0 4px",
},
},
file.name
),
]),
h("i", {
class: "el-icon-close",
on: {
["click"]: () =>
this.fileRemoveHandler(
file,
i.field
),
},
}),
];
},
}
: "",
},
this.optionsRender(h, i)
),
]
)
);
}
});
return dom;
})()
),
]
),
h("template", { slot: "footer" }, [
h(
"el-button",
@ -229,7 +258,14 @@ export default {
? info._params.map((i) =>
h("el-option", {
props: {
label: i.name || i.mingcheng || i.label || i.key || i.value || i.id || i.no,
label:
i.name ||
i.mingcheng ||
i.label ||
i.key ||
i.value ||
i.id ||
i.no,
value: i.id || i.value,
},
})
@ -320,6 +356,7 @@ export default {
this.form[key] = "";
}
}
this.form["faburiqi"] = this.$moment(new Date()).format("YYYY-MM-DD");
this.$refs["elForm"].clearValidate();
},
show() {
@ -349,34 +386,37 @@ export default {
this.$integrateData(this.form, res);
this.formInfo.forEach((i) => {
if (i && (i.edit_input === "file" || i.edit_input === 'files')) {
res[i._relations.link_with_name] ? (
this.file[i.field] = res[i._relations.link_with_name] instanceof Array ? res[i._relations.link_with_name].map(i => {
return {
name: i?.name,
url: i?.url,
response: i
}
}) : [{
name: res[i._relations.link_with_name]?.name,
url: res[i._relations.link_with_name]?.url,
response: res[i._relations.link_with_name]
}]
) : this.file[i.field] = []
if (i && (i.edit_input === "file" || i.edit_input === "files")) {
res[i._relations.link_with_name]
? (this.file[i.field] =
res[i._relations.link_with_name] instanceof Array
? res[i._relations.link_with_name].map((i) => {
return {
name: i?.name,
url: i?.url,
response: i,
};
})
: [
{
name: res[i._relations.link_with_name]?.name,
url: res[i._relations.link_with_name]?.url,
response: res[i._relations.link_with_name],
},
])
: (this.file[i.field] = []);
}
if (i.field === 'shenhebumen') {
this.form['shenhebumen'] = res[i._relations.link_with_name]?.dept_id
if (i.field === "shenhebumen") {
this.form["shenhebumen"] = res[i._relations.link_with_name]?.dept_id;
}
this.form = Object.assign({}, this.form);
this.originalForm = deepCopy(res)
this.originalForm = deepCopy(res);
});
console.log('11',this.form)
},
submit() {
let promiseAll = []
let promiseAll = [];
if (this.type === "add") {
if (this.form.hasOwnProperty("id")) {
delete this.form.id;
@ -384,12 +424,11 @@ export default {
//TODO:
if (/^\/manage/.test(this.$route.path)) {
this.form['zhuangtai'] = 0
this.form["zhuangtai"] = 0;
}
if (this.tableName === 'materials') {
this.form['leixing'] = Number(this.$route.meta.params.type);
if (this.tableName === "materials") {
this.form["leixing"] = Number(this.$route.meta.params.type);
}
}
if (this.type === "editor") {
Object.defineProperty(this.form, "id", {
@ -398,81 +437,110 @@ export default {
configurable: true,
writable: true,
});
}
this.$refs["elForm"].validate((validate) => {
if (validate) {
let copyForm = deepCopy(this.form)
let copyForm = deepCopy(this.form);
this.formInfo.forEach((info) => {
if (info._relations?.link_relation === 'newHasMany' || info._relations?.link_relation === 'hasMany') {
if (
info._relations?.link_relation === "newHasMany" ||
info._relations?.link_relation === "hasMany"
) {
if (this.originalForm[info._relations.link_with_name]) {
this.originalForm[info._relations.link_with_name].map(i => {
promiseAll.push(destroy({
id: i.id,
table_name: info._relations.link_table_name
}))
})
this.originalForm[info._relations.link_with_name].map((i) => {
promiseAll.push(
destroy({
id: i.id,
table_name: info._relations.link_table_name,
})
);
});
}
}
if (info.field === 'biaoqian') {
copyForm[info._relations.link_with_name].forEach(i => delete i.id)
delete copyForm[info.field]
return
if (info.field === "biaoqian") {
copyForm[info._relations.link_with_name].forEach(
(i) => delete i.id
);
delete copyForm[info.field];
return;
}
if (copyForm[info._relations?.link_with_name]?.length > 0) {
delete copyForm[info.field]
delete copyForm[info.field];
}
if (info._relations?.link_relation === 'newHasMany' || info._relations?.link_relation === 'hasMany') {
if (info.edit_input === 'files') {
copyForm[info._relations.link_with_name] = this.file[info.field]?.map(i => {
let copyRelation = i?.response ? deepCopy(i?.response) : ''
delete copyRelation.id
if (
info._relations?.link_relation === "newHasMany" ||
info._relations?.link_relation === "hasMany"
) {
if (info.edit_input === "files") {
copyForm[info._relations.link_with_name] = this.file[
info.field
]?.map((i) => {
let copyRelation = i?.response ? deepCopy(i?.response) : "";
delete copyRelation.id;
return {
upload_id: i?.response?.id,
...copyRelation
}
...copyRelation,
};
});
} else {
copyForm[info._relations.link_with_name] = copyForm[info.field]?.map( i => {
let copyRelation = info._params.find(param => param[info._relations?.foreign_key] === i) ? deepCopy(info._params.find(param => param[info._relations?.foreign_key] === i)) : ''
delete copyRelation.id
copyForm[info._relations.link_with_name] = copyForm[
info.field
]?.map((i) => {
let copyRelation = info._params.find(
(param) => param[info._relations?.foreign_key] === i
)
? deepCopy(
info._params.find(
(param) => param[info._relations?.foreign_key] === i
)
)
: "";
delete copyRelation.id;
return {
[info._relations.foreign_key]: i,
...copyRelation
}
})
...copyRelation,
};
});
}
delete copyForm[info.field]
delete copyForm[info.field];
}
if (info._relations?.link_relation === 'newHasOne' || info._relations?.link_relation === 'hasOne') {
if (info.edit_input === 'file') {
if (
info._relations?.link_relation === "newHasOne" ||
info._relations?.link_relation === "hasOne"
) {
if (info.edit_input === "file") {
copyForm[info._relations.link_with_name] = [
{
upload_id: this.file[info.field]?.response?.id,
...this.file[info.field]
}
...this.file[info.field],
},
];
} else {
let copyRelation = deepCopy(info._params.find(param => param.id == this.form[info.field]))
let copyRelation = deepCopy(
info._params.find(
(param) => param.id == this.form[info.field]
)
);
if (copyRelation) {
delete copyRelation.id
delete copyRelation.id;
copyForm[info._relations.link_with_name] = [
{
id: this.form[info._relations?.link_with_name]?.id,
[info.field === 'shenhebumen' ? 'dept_id' : info._relations.foreign_key]: this.form[info.field],
[info.field === "shenhebumen"
? "dept_id"
: info._relations.foreign_key]: this.form[info.field],
...copyRelation,
}
]
},
];
}
}
delete copyForm[info.field]
delete copyForm[info.field];
}
if (!copyForm[info._relations?.link_with_name]) {
delete copyForm[info._relations?.link_with_name]
delete copyForm[info._relations?.link_with_name];
}
// if (info._relations?.link_with_name) {
// if (info.edit_input === "files" || info.edit_input === "file") {
@ -486,16 +554,16 @@ export default {
// }
// }
});
promiseAll.push(save(Object.assign(copyForm, { table_name: this.tableName })))
Promise.all(promiseAll).then(
(res) => {
this.$Message.success({
content: `${this.type === "add" ? "新增" : "编辑"}成功`,
});
this.$emit("refresh");
this.hidden();
}
promiseAll.push(
save(Object.assign(copyForm, { table_name: this.tableName }))
);
Promise.all(promiseAll).then((res) => {
this.$Message.success({
content: `${this.type === "add" ? "新增" : "编辑"}成功`,
});
this.$emit("refresh");
this.hidden();
});
}
});
},
@ -529,7 +597,25 @@ export default {
this.form[i.field] = [];
}
if (i._relations) {
this.form[i._relations?.link_with_name] = []
this.form[i._relations?.link_with_name] = [];
}
//
if (i.field === 'shenhebumen') {
this.form[i.field] = this.$store.state.user.department?.id
}
if (i.field === "faburiqi") {
this.form[i.field] = this.$moment(new Date()).format(
"YYYY-MM-DD"
);
}
if (
i.field === "fujian" &&
/^\/manage\/form/.test(this.$route.fullPath)
) {
this.rules[i.field] = [
{ required: true, message: `请选择${i.name}` },
];
}
}
});
@ -564,5 +650,4 @@ export default {
color: red;
text-decoration: underline;
}
</style>

@ -314,15 +314,20 @@
:field-info="fieldInfo"
:form="form"
:file="file"
@formDialog="$refs['formDialog'].setType('add'),$refs['formDialog'].show()"
@update="(val) => ($set(file, 'fujian', val))"
@formDialog="
$refs['formDialog'].setType('add'), $refs['formDialog'].show()
"
@update="(val) => $set(file, 'fujian', val)"
></flow>
</template>
<template #biaoqian="{ fieldInfo, form, file }">
<biaoqian
:field-info="fieldInfo"
:form="form"
@update="(val) => (form['id_material_biaoqian_tags_material_id_relation'] = val)"
@update="
(val) =>
(form['id_material_biaoqian_tags_material_id_relation'] = val)
"
></biaoqian>
</template>
</dialoger>
@ -338,8 +343,11 @@
@refresh="$refs['xyTable'].getTableData()"
></imports>
<formDialog :table-name="customForm.tableName"
:form-info="form" ref="formDialog"></formDialog>
<formDialog
:table-name="customForm.tableName"
:form-info="form"
ref="formDialog"
></formDialog>
</div>
</template>
@ -376,7 +384,7 @@ export default {
flow,
biaoqian,
formDialog
formDialog,
},
mixins: [authMixin],
provide: {
@ -468,8 +476,10 @@ export default {
//
submit(scope, setType) {
let row = deepCopy(scope.row)
row.id_material_shenhebumen_depts_material_id_relation = [row.id_material_shenhebumen_depts_material_id_relation]
let row = deepCopy(scope.row);
row.id_material_shenhebumen_depts_material_id_relation = [
row.id_material_shenhebumen_depts_material_id_relation,
];
save(
Object.assign(row, {
zhuangtai: setType,
@ -506,7 +516,10 @@ export default {
[
"material_shenhebumen_depts",
async () => {
const res = await listdeptNoAuth();
const res = await listdeptNoAuth({
page: 1,
page_size: 999
});
return res;
},
],
@ -532,16 +545,19 @@ export default {
throw new Error("fields或relation格式错误");
}
fieldRes?.data?.forEach((i, index) => {
i._relations = relation.find((j) => j.link_table_name.split('_')[1] === i.field);
i._relations = relation.find(
(j) => j.link_table_name.split("_")[1] === i.field
);
if (i.select_item && typeof i.select_item === "object") {
let keys = Object.keys(i.select_item);
i._params = keys.map((key) => {
return {
key,
value: /^\d*$/.test(i.select_item[key]) ? Number(i.select_item[key]) : i.select_item[key],
value: /^\d*$/.test(i.select_item[key])
? Number(i.select_item[key])
: i.select_item[key],
};
});
console.log('pp',i._params)
}
if (i.edit_input === "file" || i.edit_input === "files") {
return;
@ -550,7 +566,9 @@ export default {
if (baseTable.get(i._relations.link_table_name)) {
baseTable
.get(i._relations.link_table_name)()
.then((res) => (i._params = res));
.then((res) => {
i._params = res.data;
});
} else {
i._params = i._relations.parameter_id
? getparameter({ id: i._relations.parameter_id }, false).then(
@ -569,9 +587,9 @@ export default {
}
});
this.form = fieldRes?.data || [];
this.table = this.form
this.form
?.filter((i) => i.list_show)
.map((i) => {
.filter((i) => {
let linkOb = {};
if (i.edit_input === "richtext") {
@ -631,30 +649,44 @@ export default {
return (
<div>
{row[link_with_name]?.map((o) => (
<p>{ o?.name || o?.no || o?.value || o?.biaoti || o?.mingcheng }</p>
<p>
{o?.name ||
o?.no ||
o?.value ||
o?.biaoti ||
o?.mingcheng}
</p>
))}
</div>
);
};
}
}
return Object.assign(
{
prop: i.field,
label: i.name,
width: i.width,
fixed: i.is_fixed,
},
linkOb
);
if (!/\/manage\/rule/.test(this.$route.fullPath) &&
!!["nianfen", "bianhao", "wenjian"].find(
(j) => j === i.field
)) {
} else {
this.table.push(Object.assign(
{
prop: i.field,
label: i.name,
width: i.width,
fixed: i.is_fixed,
},
linkOb
))
}
});
this.table.unshift({
type: "index",
width: 60,
label: "序号",
});
console.log(111, this.form);
},
},

@ -272,7 +272,7 @@ export default {
async getInfo () {
this.loading = true;
this.details = await home();
const res1 = await tags({table_name: 'tags'})
const res1 = await tags({ table_name: 'tags',shifouxianshishouye: 1, zhuangtai: 1 })
this.labels = res1.tags.slice(0,10)
const res2 = await departments({table_name: 'departments'})
this.departments = res2.department.slice(0,14)

Loading…
Cancel
Save