Browse Source

项目发布优化

master
wenlele 9 months ago
parent
commit
85e0775b5e
  1. 23
      api/app/lib/controllers/auth/index.js
  2. 16
      api/app/lib/controllers/projectManagement/projectPublish.js
  3. 2
      web-screen/client/src/layout/components/header/index.js
  4. 4
      web-screen/client/src/sections/auth/actions/auth.js
  5. 2
      web-screen/client/src/sections/auth/containers/login.js
  6. 2
      web/client/src/sections/projectManagement/actions/projectPublish.js
  7. 7
      web/client/src/sections/projectManagement/components/projectModel.js
  8. 58
      web/client/src/sections/projectManagement/components/replacement.js
  9. 53
      web/client/src/sections/projectManagement/containers/projectPublish.js

23
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,

16
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,8 +57,18 @@ 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
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 {
if (id) {
message = '修改项目失败'
await models.ProjectUser.update(data, { where: { id } })
@ -65,6 +76,9 @@ async function postProjectPublish (ctx, next) {
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}`)

2
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 => {

4
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({

2
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({

2
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' }
});
}

7
web/client/src/sections/projectManagement/components/projectModel.js

@ -59,7 +59,7 @@ const ProjectModel = ({ dispatch, actions, user, modelData, close, success, proj
<Form.Item label='项目名称' name='projectName' initialValue={modelData?.projectName}
rules={[{ required: true, message: '请输入项目名称' },]}
>
<Input style={{ width: 210 }} placeholder='请输入项目名称' maxLength={15}/>
<Input style={{ width: 210 }} placeholder='请输入项目名称' maxLength={15} />
</Form.Item>
<Form.Item name='projectDescribe' label="项目描述" initialValue={modelData?.projectDescribe}
rules={[{ required: true, message: '请输入项目描述' },]}
@ -95,14 +95,15 @@ const ProjectModel = ({ dispatch, actions, user, modelData, close, success, proj
{!modelData?.id &&
<>
<Form.Item label='发布密码' name='password' initialValue={modelData?.password}
rules={[{ required: true, message: '请输入发布密码' },]}
rules={[{ required: true, }, { pattern: /^[a-zA-Z0-9]+$/, message: "请输入发布密码,至少6位数字或字母" }]}
// rules={[{ required: true, message: '请输入发布密码' },]}
>
<Input.Password autocomplete='new-password' onPaste={e => {
e.preventDefault();
}} style={{ width: 150 }} placeholder='请输入发布密码' />
</Form.Item>
<Form.Item label='确认密码' name='confirmPassword' initialValue={modelData?.confirmPassword}
rules={[{ required: true, message: '请输入确认密码' },]}
rules={[{ required: true, }, { pattern: /^[a-zA-Z0-9]+$/, message: "请输入确认密码,至少6位数字或字母" }]}
>
<Input.Password autocomplete='new-password' style={{ width: 150 }} placeholder='请输入确认密码' />
</Form.Item>

58
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 (
<Modal
// className="global-modal"
title={'重置密码'}
width={470}
open={true}
onOk={() => {
form.validateFields().then(v => {
onOk(v)
})
}}
onCancel={() => close()}
>
<Form
style={{}}
form={form}
labelAlign='right'
labelCol={{ span: 4 }} wrapperCol={{ span: 18 }}
onFinish={r => {
}}
>
<Form.Item label='发布密码' name='password'
rules={[{ required: true, }, { pattern: /^[a-zA-Z0-9]+$/, message: "请输入发布密码,至少6位数字或字母" }]}
>
<Input.Password autocomplete='new-password' onPaste={e => {
e.preventDefault();
}} style={{ width: 150 }} placeholder='请输入发布密码' />
</Form.Item>
</Form>
</Modal>
);
};
function mapStateToProps (state) {
const { auth, global } = state;
return {
user: auth.user,
actions: global.actions,
};
}
export default connect(mapStateToProps)(Replacement);

53
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 (<>
<Button type="link" onClick={() => {
@ -89,7 +92,11 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre
setCode(record?.code)
setModelData(record)
setCodeEdit(true)
}} >地址</Button></>
}} >地址</Button>
<Button type="link" onClick={() => {
setModelData(record)
setReplacement(true)
}} >重置密码</Button></>
)
}
}
@ -154,6 +161,30 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre
}}
/> : ""
}
{
replacement ?
<Replacement
close={() => {
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 &&
<Modal
@ -161,17 +192,23 @@ const ProjectPublish = ({ dispatch, actions, user, loading, publishList, webScre
width={600}
open={codeEdit}
onOk={() => {
if (code) {
dispatch(projectManagement.postProjectPublish({
id: modelData?.id,
code: code || v4(),
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
}}
>
<Input
disabled={true}
addonBefore={webScreen + '/signin?p='}
// disabled={true}
addonBefore={webScreen + '/signin?pcode='}
addonAfter={<div style={{ cursor: 'pointer' }} onClick={() => { setCode(v4()) }}><SettingOutlined />修改</div>}
value={code} />
value={code}
onChange={v => {
setCode(v.target.value);
}}
/>
</Modal>
}
</div>

Loading…
Cancel
Save