diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index 94ebe47..3ffdc25 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -159,14 +159,14 @@ async function screenlogin (ctx, next) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; - let { p, username, password } = ctx.request.body; + let { pcode, username, password } = ctx.request.body; - if (!p) { + if (!pcode) { message = '缺少pcode' throw '' } let userRes = await models.ProjectUser.findOne({ - where: { code: p }, + where: { code: pcode }, }) || {} if (!userRes.id) { @@ -189,14 +189,15 @@ async function screenlogin (ctx, next) { let userData = userRes.dataValues; let userRslt = Object.assign({ - projectName:userData.projectName, - projectType:userData.projectType, - projectDescribe:userData.projectDescribe, - monitorObject:userData.monitorObject, - id:userData.id, - del:userData.del, - createTime:userData.createTime, - account:userData.account, + projectName: userData.projectName, + projectType: userData.projectType, + projectDescribe: userData.projectDescribe, + monitorObject: userData.monitorObject, + id: userData.id, + del: userData.del, + createTime: userData.createTime, + account: userData.account, + pcode: userData.code, }, { authorized: true, token: token, diff --git a/api/app/lib/controllers/projectManagement/projectPublish.js b/api/app/lib/controllers/projectManagement/projectPublish.js index eaaf916..91d57f4 100644 --- a/api/app/lib/controllers/projectManagement/projectPublish.js +++ b/api/app/lib/controllers/projectManagement/projectPublish.js @@ -31,6 +31,7 @@ async function getProjectPublishList (ctx, next) { const { limit, page } = ctx.query let options = { where: {}, + order: [['id', 'ASC']], } if (limit) { options.limit = Number(limit) @@ -56,15 +57,28 @@ async function postProjectPublish (ctx, next) { try { const models = ctx.fs.dc.models const data = ctx.request.body - const { id, password } = data + const { id, password, projectName, replacement } = data - if (id) { - message = '修改项目失败' - await models.ProjectUser.update(data, { where: { id } }) + let findOne = await models.ProjectUser.findOne({ where: { projectName } }) + if ((!id && findOne) || (findOne && findOne.id != id)) { + message = '项目名称重复' + throw '' + } + + if (replacement) { + let pass = Hex.stringify(MD5(password)); + await models.ProjectUser.update({ password: pass, }, { where: { id } }) } else { - let passwords = Hex.stringify(MD5(password)); - await models.ProjectUser.create({ ...data, password: passwords, del: false }) + if (id) { + message = '修改项目失败' + await models.ProjectUser.update(data, { where: { id } }) + } else { + let passwords = Hex.stringify(MD5(password)); + await models.ProjectUser.create({ ...data, password: passwords, del: false }) + } } + + ctx.status = 204 } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) @@ -81,7 +95,7 @@ async function delProjectPublish (ctx, next) { const { id } = ctx.params await models.ProjectUser.destroy({ where: { id } }) - + ctx.status = 204 } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) diff --git a/web-screen/client/src/layout/components/header/index.js b/web-screen/client/src/layout/components/header/index.js index 547f9a3..ffef205 100644 --- a/web-screen/client/src/layout/components/header/index.js +++ b/web-screen/client/src/layout/components/header/index.js @@ -84,7 +84,7 @@ const Header = props => { if (item.key == 'logout') { dispatch(actions.auth.logout(user)) dispatch({ type: 'CLEAR_GLOBAL_SITE_LIST' }) //清空用户关注工地列表 - history.push(`/signin`) + history.push(`/signin?pcode=${user.pcode}`) } } const onClick1 = tab => { diff --git a/web-screen/client/src/sections/auth/actions/auth.js b/web-screen/client/src/sections/auth/actions/auth.js index b561094..6a4ed5f 100644 --- a/web-screen/client/src/sections/auth/actions/auth.js +++ b/web-screen/client/src/sections/auth/actions/auth.js @@ -17,11 +17,11 @@ export function initAuth () { export const REQUEST_LOGIN = 'REQUEST_LOGIN'; export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; export const LOGIN_ERROR = 'LOGIN_ERROR'; -export function login ({ username, password, phone, code, p }) { +export function login ({ username, password, phone, code, pcode }) { return dispatch => { dispatch({ type: REQUEST_LOGIN }); - return Request.post(ApiTable.login, { username, password, phone, code, p }) + return Request.post(ApiTable.login, { username, password, phone, code, pcode }) .then(user => { sessionStorage.setItem('user', JSON.stringify(user)); dispatch({ diff --git a/web-screen/client/src/sections/auth/containers/login.js b/web-screen/client/src/sections/auth/containers/login.js index 987e836..106b064 100644 --- a/web-screen/client/src/sections/auth/containers/login.js +++ b/web-screen/client/src/sections/auth/containers/login.js @@ -138,7 +138,7 @@ const Login = props => { form={form} onFinish={r => { form.validateFields().then(r => { - dispatch(login({ username: r.username, password: r.password, p: qs.parse(location?.search?.slice(1))?.p })) + dispatch(login({ username: r.username, password: r.password, pcode: qs.parse(location?.search?.slice(1))?.pcode })) }) .catch(err => { dispatch({ diff --git a/web/client/src/sections/projectManagement/actions/projectPublish.js b/web/client/src/sections/projectManagement/actions/projectPublish.js index bf1e2ba..3ebc812 100644 --- a/web/client/src/sections/projectManagement/actions/projectPublish.js +++ b/web/client/src/sections/projectManagement/actions/projectPublish.js @@ -32,7 +32,7 @@ export function postProjectPublish (data = {}) { data, actionType: 'POST_PROJECT_PUBLISH', url: `${ApiTable.projectPublishList}`, - msg: { option: data?.isCode ? '修改地址' : data?.id ? "编辑项目" : '新增项目' }, + msg: { option: data?.isCode ? '修改地址' : (data?.replacement ? '重置密码' : (data?.id ? "编辑项目" : '新增项目')) }, reducer: { name: 'anxinyunProject' } }); } diff --git a/web/client/src/sections/projectManagement/components/projectModel.js b/web/client/src/sections/projectManagement/components/projectModel.js index 5c4337e..df63e48 100644 --- a/web/client/src/sections/projectManagement/components/projectModel.js +++ b/web/client/src/sections/projectManagement/components/projectModel.js @@ -59,7 +59,7 @@ const ProjectModel = ({ dispatch, actions, user, modelData, close, success, proj - + { e.preventDefault(); }} style={{ width: 150 }} placeholder='请输入发布密码' /> diff --git a/web/client/src/sections/projectManagement/components/replacement.js b/web/client/src/sections/projectManagement/components/replacement.js new file mode 100644 index 0000000..682550a --- /dev/null +++ b/web/client/src/sections/projectManagement/components/replacement.js @@ -0,0 +1,58 @@ +import React, { useState, useEffect } from 'react'; +import { connect } from 'react-redux'; +import { v4 } from 'uuid'; +import moment from 'moment'; +import { Form, Input, Modal, Select, Row, Col, message } from 'antd'; +const { TextArea } = Input; + + +const Replacement = ({ dispatch, actions, user, close, onOk, }) => { + + const [form] = Form.useForm(); + + + return ( + { + form.validateFields().then(v => { + onOk(v) + }) + }} + onCancel={() => close()} + > +
{ + }} + > + + + { + e.preventDefault(); + }} style={{ width: 150 }} placeholder='请输入发布密码' /> + +
+
+ + ); +}; + + +function mapStateToProps (state) { + const { auth, global } = state; + return { + user: auth.user, + actions: global.actions, + }; +} + +export default connect(mapStateToProps)(Replacement); \ No newline at end of file diff --git a/web/client/src/sections/projectManagement/containers/projectPublish.js b/web/client/src/sections/projectManagement/containers/projectPublish.js index cda189c..480039b 100644 --- a/web/client/src/sections/projectManagement/containers/projectPublish.js +++ b/web/client/src/sections/projectManagement/containers/projectPublish.js @@ -1,11 +1,12 @@ import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; -import { Spin, Form, Input, Button, Table, Modal, Popconfirm, Tooltip } from 'antd'; +import { Spin, Form, Input, Button, Table, Modal, Popconfirm, Tooltip, message } from 'antd'; import { SettingOutlined } from '@ant-design/icons'; import { push } from 'react-router-redux'; import moment from 'moment'; import { v4 } from 'uuid'; import ProjectModel from '../components/projectModel' +import Replacement from '../components/replacement' import './style.less'; @@ -22,6 +23,7 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre const [search, setSearch] = useState({}) const [companyID, setCompanyId] = useState('') const [code, setCode] = useState('') + const [replacement, setReplacement] = useState(false) @@ -64,6 +66,7 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre title: '操作', dataIndex: 'operation', key: 'operation', + width: 300, render: (text, record, index) => { return (<> + }} >地址 + ) } } @@ -154,6 +161,30 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre }} /> : "" } + { + replacement ? + { + setModelData({}) + setReplacement(false) + }} + onOk={(item) => { + dispatch(projectManagement.postProjectPublish({ + id: modelData?.id, + password: item?.password, + replacement: true, + })).then(res => { + if (res.success) { + setModelData({}) + setReplacement(false) + projectPublishList(query) + } + }) + }} + /> : "" + } + + { codeEdit && { - dispatch(projectManagement.postProjectPublish({ - id: modelData?.id, - code: code || v4(), - isCode: true, - })).then(res => { - if (res.success) { - setCodeEdit(false) - setCode("") - setModelData({}) - } - }) + if (code) { + dispatch(projectManagement.postProjectPublish({ + id: modelData?.id, + code: code, + isCode: true, + })).then(res => { + if (res.success) { + setCodeEdit(false) + setCode("") + setModelData({}) + projectPublishList(query) + } + }) + } else { + message.warning('请填写或自动生成pcode'); + } + }} onCancel={() => { setCodeEdit(false) @@ -180,10 +217,14 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre }} > { setCode(v4()) }}>修改} - value={code} /> + value={code} + onChange={v => { + setCode(v.target.value); + }} + /> }