From e2f055affaa7f22223c596a4b709624f4817efc1 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Wed, 27 Jul 2022 09:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weapp/src/app.config.js | 4 +- .../packages/changePassword/index.config.js | 3 + weapp/src/packages/changePassword/index.jsx | 63 +++++++++++++++++++ weapp/src/packages/changePassword/index.scss | 6 ++ .../changePassword/success/index.config.js | 3 + .../packages/changePassword/success/index.jsx | 19 ++++++ .../changePassword/success/index.scss | 0 weapp/src/packages/patrol/index.jsx | 2 +- weapp/src/packages/patrolView/index.jsx | 62 ++++++++++-------- weapp/src/pages/auth/login/login.jsx | 4 ++ weapp/src/pages/user/index.jsx | 25 +++++--- weapp/src/services/api.js | 6 +- 12 files changed, 159 insertions(+), 38 deletions(-) create mode 100644 weapp/src/packages/changePassword/index.config.js create mode 100644 weapp/src/packages/changePassword/index.jsx create mode 100644 weapp/src/packages/changePassword/index.scss create mode 100644 weapp/src/packages/changePassword/success/index.config.js create mode 100644 weapp/src/packages/changePassword/success/index.jsx create mode 100644 weapp/src/packages/changePassword/success/index.scss diff --git a/weapp/src/app.config.js b/weapp/src/app.config.js index 0fefdbef..db0918a6 100644 --- a/weapp/src/app.config.js +++ b/weapp/src/app.config.js @@ -8,7 +8,9 @@ export default { 'root': 'packages/', 'pages': [ 'patrol/index', - 'patrolView/index' + 'patrolView/index', + 'changePassword/index', + 'changePassword/success/index' ] }], permission: { diff --git a/weapp/src/packages/changePassword/index.config.js b/weapp/src/packages/changePassword/index.config.js new file mode 100644 index 00000000..4db035c1 --- /dev/null +++ b/weapp/src/packages/changePassword/index.config.js @@ -0,0 +1,3 @@ +export default { + navigationBarTitleText: '修改密码' +} \ No newline at end of file diff --git a/weapp/src/packages/changePassword/index.jsx b/weapp/src/packages/changePassword/index.jsx new file mode 100644 index 00000000..b3084332 --- /dev/null +++ b/weapp/src/packages/changePassword/index.jsx @@ -0,0 +1,63 @@ +import React, { useState } from 'react' +import Taro from '@tarojs/taro' +import { View, Input } from '@tarojs/components' +import { AtButton } from 'taro-ui' +import request from '@/services/request' +import { putPassword } from '@/services/api' +import './index.scss' + +function Index() { + const userInfo = Taro.getStorageSync('userInfo') || null; + const [password, setPassword] = useState('') + const [password2, setPassword2] = useState('') + + function confirm() { + if (!password) { + Taro.showToast({ title: '请输入密码' }) + return + } else if (password !== password2) { + Taro.showToast({ title: '两次输入的密码不一致' }) + return + } else { + Taro.showModal({ + title: '提示', + content: '确定修改吗', + success: function (res) { + if (res.confirm) { + Taro.showLoading({ + title: '修改中' + }) + request.put(putPassword(userInfo.id), { password }).then(res => { + Taro.hideLoading() + if (res.statusCode == 200 || res.statusCode == 204) { + Taro.removeStorageSync('token') + Taro.removeStorageSync('userInfo') + Taro.reLaunch({ url: '/packages/changePassword/success/index' }) + } + }) + } + } + }) + } + } + + return ( + + + 手机号码: + + + + 新的密码: + setPassword(e.detail.value)} /> + + + 再次输入新的密码: + setPassword2(e.detail.value)} /> + + 确认 + + ) +} + +export default Index \ No newline at end of file diff --git a/weapp/src/packages/changePassword/index.scss b/weapp/src/packages/changePassword/index.scss new file mode 100644 index 00000000..34dd1178 --- /dev/null +++ b/weapp/src/packages/changePassword/index.scss @@ -0,0 +1,6 @@ +.page { + height: 100vh; + width: 100vw; + background-color: #f6f6f6; + +} \ No newline at end of file diff --git a/weapp/src/packages/changePassword/success/index.config.js b/weapp/src/packages/changePassword/success/index.config.js new file mode 100644 index 00000000..7bbbb6ea --- /dev/null +++ b/weapp/src/packages/changePassword/success/index.config.js @@ -0,0 +1,3 @@ +export default { + navigationBarTitleText: '修改密码' +} \ No newline at end of file diff --git a/weapp/src/packages/changePassword/success/index.jsx b/weapp/src/packages/changePassword/success/index.jsx new file mode 100644 index 00000000..54468d51 --- /dev/null +++ b/weapp/src/packages/changePassword/success/index.jsx @@ -0,0 +1,19 @@ +import React from 'react' +import Taro from '@tarojs/taro' +import { View, Image } from '@tarojs/components' +import { AtButton } from 'taro-ui' + +function Index() { + function handleClick() { + Taro.reLaunch({ url: '/pages/auth/login/login' }) + } + + return ( + + 修改成功 + 返回登录 + + ) +} + +export default Index diff --git a/weapp/src/packages/changePassword/success/index.scss b/weapp/src/packages/changePassword/success/index.scss new file mode 100644 index 00000000..e69de29b diff --git a/weapp/src/packages/patrol/index.jsx b/weapp/src/packages/patrol/index.jsx index fae9ad98..b0574aed 100644 --- a/weapp/src/packages/patrol/index.jsx +++ b/weapp/src/packages/patrol/index.jsx @@ -377,12 +377,12 @@ const Index = () => { handleInput(e, 'content')} disabled={isView} + maxLength={50} /> { reportType === 'patrol' ? diff --git a/weapp/src/packages/patrolView/index.jsx b/weapp/src/packages/patrolView/index.jsx index a8863200..49c0ec2c 100644 --- a/weapp/src/packages/patrolView/index.jsx +++ b/weapp/src/packages/patrolView/index.jsx @@ -18,13 +18,17 @@ function Index() { const [isPatrol, setIsPatrol] = useState(true) const [datePicker, setDatePicker] = useState(moment().format('YYYY-MM-DD')) const [listData, setListData] = useState([]) - const [inputSite, setInputSite] = useState('') - const [page, setPage] = useState(0) - const [total, setTotal] = useState(0) - const [num, setNum] = useState(Math.random()) + const [showListData, setShowListData] = useState([]) + const [filterText, setFilterText] = useState('') const [systemInfo, setSystemInfo] = useState('') - const userInfo = Taro.getStorageSync('userInfo') || {}; + useEffect(() => { + getList() + }, [datePicker]) + + useEffect(() => { + setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) + }, [isPatrol]) function dealError(error) { Taro.showToast({ @@ -34,11 +38,17 @@ function Index() { }); throw new Error(error); } - useEffect(() => { - request.get(getReportList(), {}, { hideErrorToast: true, hideLoading: true }).then(res => { + const getList = () => { + Taro.showLoading({ title: '加载中' }) + request.get( + getReportList(), + { startTime: datePicker + ' 00:00:00', endTime: datePicker + ' 23:59:59' }, + { hideErrorToast: true, hideLoading: true } + ).then(res => { + Taro.hideLoading() if (res.statusCode == 200) { - // console.log(res); setListData(res.data) + setShowListData(res.data.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) return res.data; } else { dealError(res.data.message || '请求出错'); @@ -46,13 +56,11 @@ function Index() { }, err => { dealError(err.message || '请求出错'); }); - }, []) + } useDidShow(() => { let refresh = Taro.getStorageSync('refresh'); // 返回列表需要刷新 if (refresh) { - setPage(0) - setNum(Math.random()) Taro.removeStorageSync('refresh'); // 返回列表需要刷新 } Taro.getSystemInfo({ @@ -72,25 +80,21 @@ function Index() { setDatePicker(e.detail.value); } - const handleConfirm = () => { - setPage(0) - setListData([]); - setTotal(0); - setNum(Math.random()) + const handleConfirm = e => { + let nextList = listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve') + nextList = nextList.filter(item => item.road.includes(e.detail.value)) + setShowListData(nextList) } const handleInput = e => { - setInputSite(e.detail.value); + setFilterText(e.detail.value); if (!e.detail.value) { - setPage(0) - setListData([]); - setTotal(0); - setNum(Math.random()) + setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')); } } const handleDetail = index => { - Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${listData[index].id}` }) + Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${showListData[index].id}` }) } return ( @@ -109,20 +113,27 @@ function Index() { 日期: - + {datePicker || '请选择'} - + { - listData && listData.length > 0 ? listData && listData.map((e, index) => { + showListData && showListData.length > 0 ? showListData && showListData.map((e, index) => { return ( handleDetail(index)}> @@ -144,5 +155,4 @@ function Index() { ) } - export default Index diff --git a/weapp/src/pages/auth/login/login.jsx b/weapp/src/pages/auth/login/login.jsx index 5f45438f..4a4b7a66 100644 --- a/weapp/src/pages/auth/login/login.jsx +++ b/weapp/src/pages/auth/login/login.jsx @@ -18,6 +18,10 @@ const LoginPage = (props) => { const [password, setPassword] = useState(''); const doLogin = () => { + if (!username || !password) { + Taro.showToast({ title: '请输入账号和密码', icon: 'none' }) + return + } login(getLoginUrl(), { phone: username, password }).then(res => { Taro.reLaunch({ url: '/pages/home/index' diff --git a/weapp/src/pages/user/index.jsx b/weapp/src/pages/user/index.jsx index b1a7009d..3cb03da2 100644 --- a/weapp/src/pages/user/index.jsx +++ b/weapp/src/pages/user/index.jsx @@ -17,17 +17,24 @@ const { webUrl } = cfg; const Index = ({ ...props }) => { const userInfo = Taro.getStorageSync('userInfo') || {}; - const goRedirect = () => { - + const changePassword = () => { + Taro.navigateTo({ url: '/packages/changePassword/index' }) } const onLogout = () => { - logout(getLogoutUrl()).then(() => { - Taro.reLaunch({ - url: '/pages/auth/login/login' - }); - }); - + Taro.showModal({ + title: '提示', + content: '确定退出登录吗', + success: function (res) { + if (res.confirm) { + logout(getLogoutUrl()).then(() => { + Taro.reLaunch({ + url: '/pages/auth/login/login' + }); + }); + } + } + }) } return ( @@ -48,7 +55,7 @@ const Index = ({ ...props }) => { - goRedirect(2)} style={{ marginTop: '2rpx' }}> + 修改密码 diff --git a/weapp/src/services/api.js b/weapp/src/services/api.js index ba5558e2..cecf30b2 100644 --- a/weapp/src/services/api.js +++ b/weapp/src/services/api.js @@ -24,10 +24,14 @@ export const getReportDetail = id => { // 删除上报 export const delReport = id => { - console.log(id) return `/report/${id}`; }; +// 修改密码 +export const putPassword = id => { + return `/department/user/${id}/password`; +}; + // 获取道路路段 export const getRoadSection = () => { return `/road/section`;