From 74a509c812c2f5df6153d2f9b8ee2e8873d5bbc1 Mon Sep 17 00:00:00 2001
From: xy <271556543@qq.com>
Date: Wed, 2 Aug 2023 15:33:26 +0800
Subject: [PATCH] 2023-8-2
---
src/api/system/department.js | 63 ++--
src/const/addProps.js | 3 +-
src/store/modules/reception.js | 7 +-
src/store/modules/user.js | 276 ++++++++--------
src/views/component/dialog.vue | 487 +++++++++++++++++------------
src/views/component/table.vue | 84 +++--
src/views/reception/home/index.vue | 2 +-
7 files changed, 526 insertions(+), 396 deletions(-)
diff --git a/src/api/system/department.js b/src/api/system/department.js
index 262b277..8fb15ee 100644
--- a/src/api/system/department.js
+++ b/src/api/system/department.js
@@ -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
+ })
+}
diff --git a/src/const/addProps.js b/src/const/addProps.js
index edd8a70..0a51360 100644
--- a/src/const/addProps.js
+++ b/src/const/addProps.js
@@ -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',
diff --git a/src/store/modules/reception.js b/src/store/modules/reception.js
index af9372e..1dc5354 100644
--- a/src/store/modules/reception.js
+++ b/src/store/modules/reception.js
@@ -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] = ''
}
}
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index c288974..00a74b5 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -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
}
diff --git a/src/views/component/dialog.vue b/src/views/component/dialog.vue
index f121b41..ff45242 100644
--- a/src/views/component/dialog.vue
+++ b/src/views/component/dialog.vue
@@ -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;
}
-
diff --git a/src/views/component/table.vue b/src/views/component/table.vue
index 945ad66..03742bb 100644
--- a/src/views/component/table.vue
+++ b/src/views/component/table.vue
@@ -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)"
>
{ o?.name || o?.no || o?.value || o?.biaoti || o?.mingcheng }
++ {o?.name || + o?.no || + o?.value || + o?.biaoti || + o?.mingcheng} +
))}