提交 c630a5c1 作者: 吴佳伟

fix: 修复bug及修改登录方式为验证码

上级 78020c8b
......@@ -3,7 +3,7 @@ import { otherHttp } from '/@/utils/http/axios'
enum Api {
getUserInfo = '/sys/user/login/setting/getUserData', // 查询登录用户信息
logout = '/sys/logout', // 登出
sysLogin = '/sys/mLogin', // 登陆
sysLogin = '/app/user/login', // 登陆
dictList = '/sys/dict/queryAllDictItems', // 获取字典数据
location = '/tianditu/geocode', // 根据经纬度获取地址
sysSmsCode = '/app/user/getSmsCode', // 短信验证码
......
......@@ -187,7 +187,18 @@
"backgroundColorBottom": "#F2F2F2",
"onReachBottomDistance": 50,
"app-plus": {
"titleNView": {}
"titleNView": {
"titleSize": "20",
"buttons": [
{
"text": "重置",
"fontSrc": "/static/uni.ttf",
"color": "#fff",
"fontSize": "28rpx",
"width": "auto"
}
]
}
}
}
},
......
......@@ -61,17 +61,19 @@
isLogin: false,
loading: false,
text: defaultText,
countdown: 0, // 倒计时秒数
countdownTimer: null, // 倒计时定时器
form: {
rules: [
{
name: 'username',
rule: ['required'],
msg: ['请输入手机号/账号'],
msg: ['请输入手机号'],
},
{
name: 'password',
name: 'code',
rule: ['required'],
msg: ['请输入码'],
msg: ['请输入验证码'],
},
{
name: 'read',
......@@ -88,7 +90,7 @@
],
data: {
username: '',
password: '',
code: '',
read: false,
deviceId: '',
},
......@@ -97,9 +99,9 @@
// TODO: 开发环境快速填入账户密码,并默认勾选已读隐私政策和服务协议
if (isDevMode()) {
model.form.data.username = 'admin'
model.form.data.password = 'ZzqEUxdqARrd!aeH'
model.form.data.read = true
model.form.data.username = ''
model.form.data.code = ''
model.form.data.read = false
}
/**
......@@ -111,7 +113,7 @@
// 登录参数
const params = {
username: model.form.data.username,
password: model.form.data.password,
captcha: model.form.data.code,
}
// 短信登录
......@@ -141,6 +143,49 @@
}
})
}
/**
* 获取验证码
*/
function smsCode() {
form?.value.validator(model.form.data, model.form.rulesPhone).then(async (res: { isPassed: boolean }) => {
if (res.isPassed) {
// 如果已经在倒计时中,不重复发送
if (model.countdown > 0) {
return
}
const params = {
phone: model.form.data.phone,
}
API.sysSmsCode(params)
.then(async (body) => {
console.log('body', body)
// 开始倒计时
startCountdown()
})
.catch(() => {
// 即使请求失败也显示倒计时,防止重复点击
startCountdown()
})
}
})
}
/**
* 开始倒计时
*/
function startCountdown() {
model.countdown = 60
model.countdownTimer = setInterval(() => {
model.countdown--
if (model.countdown <= 0) {
clearInterval(model.countdownTimer)
model.countdownTimer = null
}
}, 1000)
}
/**
* 跳转到门户页
......@@ -232,7 +277,7 @@
:required="false"
clearable
trim
placeholder="请输入手机号/账号"
placeholder="请输入手机号"
v-model="model.form.data.username"
name="mobile"
backgroundColor="transparent"
......@@ -247,26 +292,29 @@
</fui-input>
<fui-input
height="100rpx"
class="input"
password
autocomplete="new-password"
code
:required="false"
clearable
trim
placeholder="请输入密码"
v-model="model.form.data.password"
name="code"
marginTop="50"
:padding="['20rpx', '32rpx']"
placeholder="请输入验证码"
:bottomLeft="0"
marginTop="10"
v-model="model.form.data.code"
backgroundColor="transparent"
borderColor="#DDDDDD"
>
<template #left>
<view class="fui-left__icon mr-2">
<fui-icon name="lock" color="#333" :size="48" />
<fui-icon name="keyboard" color="#333" :size="48" />
</view>
</template>
<fui-button
width="200rpx"
height="64rpx"
:background="model.countdown > 0 ? '#CCCCCC' : '#67c17a'"
:color="model.countdown > 0 ? '#67c17a' : '#fff'"
@click="smsCode"
:size="28"
:disabled="model.countdown > 0"
:text="model.countdown > 0 ? `${model.countdown}秒后重试` : '获取验证码'"
/>
</fui-input>
<view class="btn__box flex-center p-32rpx box-border">
<fui-button
......
......@@ -22,11 +22,6 @@
msg: ['请输入手机号'],
},
{
name: 'password',
rule: ['required'],
msg: ['请输入密码'],
},
{
name: 'code',
rule: ['required'],
msg: ['请输入验证码'],
......
......@@ -4,10 +4,7 @@
import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu'
import { useDictStore } from '@/store/modules/dict'
import { areaTree } from '@/utils/areaData'
const dictStore = useDictStore()
const userStore = useUserStore()
const globSetting = useGlobSetting()
onLoad((option) => {
......@@ -95,8 +92,41 @@
const { show, options, form } = toRefs(pageData)
function initDict() {
console.log(dictStore.getDictList)
pageData.options.address = areaTree
nongjifuwu.cascaderHn().then((res) => {
pageData.options.address = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
}
function getScope(scope: any) {
if (!scope || !pageData.options.address) {
return []
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(pageData.options.address, value.trim())
labels.push(text)
}
return labels.join(' / ')
}
function getDetails(id) {
......@@ -139,7 +169,7 @@
}
function handleChangeAddress(e) {
pageData.form.scope = e.text.join('/')
pageData.form.scope = e.value.join(',')
pageData.show.address = false
}
const toastRef = ref()
......@@ -217,16 +247,8 @@
<view class="form-item required flex align-center" style="padding: 20rpx 10rpx">
<text class="label">服务范围</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !form.scope }">
{{ form.scope || '请选择省/市/区县' }}
</text>
</view>
</view>
<view class="form-item required flex align-center" style="padding: 20rpx 10rpx">
<text class="label">所在地区</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !form.scope }">
{{ form.scope || '请选择省/市/区县' }}
<text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text>
</view>
</view>
......@@ -240,11 +262,13 @@
/>
<fui-input
required
type="number"
label="联系方式"
placeholder="请输入联系方式"
v-model="form.phone"
labelSize="28"
label-width="180"
:maxlength="11"
/>
</view>
<view class="mt20">
......@@ -263,13 +287,13 @@
<view class="time-range">
<view class="time-input" @click="show.time1 = true">
<text class="time-text" :class="{ placeholder: !form.startTime }">
{{ form.startTime || '作业开始时间' }}
{{ form.startTime || '开始时间' }}
</text>
</view>
<text class="time-separator">-</text>
<view class="time-input" @click="show.time2 = true">
<text class="time-text" :class="{ placeholder: !form.endTime }">
{{ form.endTime || '作业结束时间' }}
{{ form.endTime || '结束时间' }}
</text>
</view>
</view>
......
......@@ -4,10 +4,7 @@
import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu'
import { useDictStore } from '@/store/modules/dict'
import { areaTree } from '@/utils/areaData'
const dictStore = useDictStore()
const userStore = useUserStore()
const globSetting = useGlobSetting()
onLoad((option) => {
......@@ -82,8 +79,41 @@
const { show, options, form } = toRefs(pageData)
function initDict() {
console.log(dictStore.getDictList)
pageData.options.address = areaTree
nongjifuwu.cascaderHn().then((res) => {
pageData.options.address = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
}
function getScope(scope: any) {
if (!scope || !pageData.options.address) {
return []
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(pageData.options.address, value.trim())
labels.push(text)
}
return labels.join(' / ')
}
function getDetails(id) {
......@@ -175,7 +205,7 @@
})
}
function handleChangeAddress(e) {
pageData.form.scope = e.text.join('/')
pageData.form.scope = e.value.join(',')
pageData.show.address = false
}
</script>
......@@ -204,8 +234,8 @@
<view class="form-item required flex align-center" style="padding: 20rpx 10rpx">
<text class="label">服务范围</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !form.scope }">
{{ form.scope || '请选择省/市/区县' }}
<text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text>
</view>
</view>
......
......@@ -5,6 +5,7 @@
import * as NongjifuwuAPI from '@/api/model/nongjifuwu'
import Navigate from '@/utils/page/navigate'
import { s } from 'vite/dist/node/types.d-aGj9QkWt'
onLoad((option) => {
pageData.search.serviceType = Number(option.type) || 1
......@@ -17,9 +18,14 @@
getCascader()
})
const options = ref([])
const pageData = reactive({
loading: false,
show: {
time: false,
classify: false,
address: false,
},
options: [],
// 分类标签
categoryTabs: [
{ id: 1, name: '找农机' },
......@@ -29,6 +35,7 @@
pageNo: 1,
pageSize: 10,
serviceType: 1,
scope: null,
},
farmMachineList: [],
total: 0,
......@@ -47,9 +54,22 @@
})
}
function search() {
pageData.loading = true
NongjifuwuAPI.farmMachineList(pageData.search)
.then((res) => {
const { records, total } = res
pageData.farmMachineList = records
pageData.total = total
})
.finally(() => {
pageData.loading = false
})
}
function getCascader() {
NongjifuwuAPI.cascaderHn().then((res) => {
options.value = res[0].children;
pageData.options = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
}
......@@ -87,8 +107,8 @@
}
function getScope(scope: any) {
if (!scope || !options.value || options.value.length === 0) {
return []
if (!scope || !pageData.options || pageData.options.length === 0) {
return ''
}
const values = scope.split(',')
......@@ -98,7 +118,7 @@
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.label
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
......@@ -111,13 +131,26 @@
}
for (const value of values) {
const label = findLabel(options.value, value.trim())
labels.push(label)
const text = findLabel(pageData.options, value.trim())
labels.push(text)
}
return labels.join(' / ')
return labels ? labels.join(' / ') : ''
}
function handleChangeAddress(e) {
pageData.search.scope = e.value.join(',')
pageData.show.address = false
// 触发搜索
search()
}
onNavigationBarButtonTap(() => {
pageData.search.scope = null
search()
})
onReachBottom(() => {
console.log('触底了')
if (pageData.total <= pageData.farmMachineList.length) return
......@@ -131,8 +164,8 @@
<view class="codefun-flex-col group_2">
<view class="codefun-flex-row codefun-justify-between section_2">
<text class="font_2 text_2">服务区域</text>
<view class="codefun-flex-row codefun-items-center">
<text class="font_2 text_3">选择市县乡镇</text>
<view class="codefun-flex-row codefun-items-center" @click="pageData.show.address = true">
<text class="font_2 text_3">{{ getScope(pageData.search.scope) || '选择区域' }}</text>
<image
class="codefun-shrink-0 image_7 codefun-ml-4"
src="/static/images/codefun/774cfe989f8417dc655fb301635f5893.png"
......@@ -316,6 +349,14 @@
<view style="font-size: 24rpx">发布</view>
</view>
</fui-fab>
<fui-picker
:show="pageData.show.address"
:options="pageData.options"
:linkage="true"
:layer="3"
@change="handleChangeAddress"
@cancel="pageData.show.address = false"
/>
<ApplyDialog ref="applyDialogRef" />
<fui-loading isFixed v-if="pageData.loading" backgroundColor="rgba(0, 0, 0, 0.4)" />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论