fix: 添加页面统一修改样式。

This commit is contained in:
tianyongbao
2026-02-08 14:27:39 +08:00
parent 98fd350b9e
commit 74b1dbd0af
12 changed files with 1684 additions and 584 deletions

View File

@@ -1,90 +1,94 @@
<template>
<view class="container" style="paddingBottom:1rpx;">
<view class="section">
<view class="section-title">{{ title}}</view>
<view class="form-view">
<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" label-width="auto"
:labelStyle="{ color: '#333333', fontSize: '30rpx' }">
<u-form-item label="姓名" prop="name" required >
<u--input v-model="form.name" placeholder="请填写姓名"
inputAlign="right" border="none"></u--input>
<view class="section">
<view class="section-title">{{ title }}</view>
<view class="form-view">
<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" label-width="140rpx"
:labelStyle="{ color: '#333333', fontSize: '30rpx', marginRight: '24rpx' }">
<u-form-item label="姓名" prop="name" required>
<u--input v-model="form.name" placeholder="请填写姓名" maxlength="30"
inputAlign="left" :customStyle="getInputStyle('name')"></u--input>
</u-form-item>
<u-form-item label="昵称" prop="nickName" required >
<u--input v-model="form.nickName" placeholder="请填写昵称"
inputAlign="right" border="none"></u--input>
<u-form-item label="昵称" prop="nickName" required>
<u--input v-model="form.nickName" placeholder="请填写昵称" maxlength="30"
inputAlign="left" :customStyle="getInputStyle('nickName')"></u--input>
</u-form-item>
<u-form-item label="类型" prop="typeName" required @click="handleType">
<u--input v-model="form.typeName" disabled disabledColor="#ffffff" placeholder="请选择类型"
inputAlign="right" border="none"></u--input>
<u-icon slot="right" name="arrow-down"></u-icon>
<u-form-item label="类型" prop="typeName" required @click="handleType">
<view class="input-with-arrow">
<u--input v-model="form.typeName" disabled disabledColor="#ffffff" placeholder="请选择类型"
inputAlign="left" :customStyle="getInputStyle('typeName')"></u--input>
<text class="arrow-icon"></text>
</view>
</u-form-item>
<u-form-item label="生日" prop="birthday" required @click="selectBirthday()">
<u--input v-model="form.birthday" disabled disabledColor="#ffffff" placeholder="请选择生日" inputAlign="right" border="none"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="性别" prop="sexName" required @click="handleSex">
<u--input v-model="form.sexName" disabled disabledColor="#ffffff" placeholder="请选择性别"
inputAlign="right" border="none"></u--input>
<u-icon slot="right" name="arrow-down"></u-icon>
<view class="input-with-arrow">
<u--input v-model="form.birthday" disabled disabledColor="#ffffff" placeholder="请选择生日"
inputAlign="left" :customStyle="getInputStyle('birthday')"></u--input>
<text class="arrow-icon"></text>
</view>
</u-form-item>
<u-form-item label="身份证" prop="identityCard" >
<u--input v-model="form.identityCard" placeholder="请填写身份证"
inputAlign="right" border="none"></u--input>
<u-form-item label="性别" prop="sexName" required @click="handleSex">
<view class="input-with-arrow">
<u--input v-model="form.sexName" disabled disabledColor="#ffffff" placeholder="请选择性别"
inputAlign="left" :customStyle="getInputStyle('sexName')"></u--input>
<text class="arrow-icon"></text>
</view>
</u-form-item>
<u-form-item label="身" prop="height" >
<u--input v-model="form.height" placeholder="请填写身"
inputAlign="right" border="none">
<u-form-item label="身份证" prop="identityCard">
<u--input v-model="form.identityCard" placeholder="请填写身份证" maxlength="18"
inputAlign="left" :customStyle="getInputStyle('identityCard')"></u--input>
</u-form-item>
<u-form-item label="身高" prop="height">
<u--input v-model="form.height" placeholder="请填写身高" type="number"
inputAlign="left" :customStyle="getInputStyle('height')">
<template #suffix>
<up-text
text="CM"
></up-text>
</template></u--input>
<up-text text="CM"></up-text>
</template>
</u--input>
</u-form-item>
<u-form-item label="体重" prop="weight" >
<u--input v-model="form.weight" placeholder="请填写体重"
inputAlign="right" border="none">
<u-form-item label="体重" prop="weight">
<u--input v-model="form.weight" placeholder="请填写体重" type="number"
inputAlign="left" :customStyle="getInputStyle('weight')">
<template #suffix>
<up-text
text="KG"
></up-text>
</template></u--input>
<up-text text="KG"></up-text>
</template>
</u--input>
</u-form-item>
<u-form-item label="备注" prop="remark" labelPosition="top">
<u--textarea v-model="form.remark" placeholder="请填写备注" border="none" ></u--textarea>
<u-form-item label="备注" prop="remark" labelPosition="top">
<u--textarea v-model="form.remark" placeholder="请填写备注" inputAlign="left"
maxlength="500" style="border:2rpx solid #dcdfe6 !important; height:160rpx;"></u--textarea>
</u-form-item>
</u--form>
<view class="form-btn">
<u-button type="primary" text="提交" @click="submit"></u-button>
</u--form>
<view class="form-btn">
<u-button type="primary" text="提交" @click="submit"></u-button>
</view>
</view>
</view>
</view>
<u-toast ref="uToast"></u-toast>
<u-picker itemHeight="88" :show="showType" :columns="typeList" keyName="dictLabel" @cancel="handleTypeCancel"
@confirm="handleTypeConfirm"></u-picker>
<u-picker itemHeight="88" :show="showSex" :columns="sexList" keyName="dictLabel" @cancel="handleSexCancel"
@confirm="handleSexConfirm"></u-picker>
<u-datetime-picker
:show="birthdayShow"
mode="date"
<u-picker itemHeight="88" :show="showType" :columns="typeList" keyName="dictLabel" @cancel="handleTypeCancel"
@confirm="handleTypeConfirm"></u-picker>
<u-picker itemHeight="88" :show="showSex" :columns="sexList" keyName="dictLabel" @cancel="handleSexCancel"
@confirm="handleSexConfirm"></u-picker>
<u-datetime-picker
:show="birthdayShow"
mode="date"
:minDate="-2209017600000"
ref="birthdayRef"
@cancel="birthdayShow=false"
@confirm="birthdayConfirm"
itemHeight="88"
></u-datetime-picker>
ref="birthdayRef"
@cancel="birthdayShow=false"
@confirm="birthdayConfirm"
itemHeight="88"
></u-datetime-picker>
</view>
</template>
<script setup>
import { getPerson,addPerson, updatePerson } from '@/api/health/person'
import { getPerson, addPerson, updatePerson } from '@/api/health/person'
const { proxy } = getCurrentInstance()
import { getDicts } from '@/api/system/dict/data.js'
import { getDicts } from '@/api/system/dict/data.js'
import dayjs from 'dayjs'
import {onLoad,onReady} from "@dcloudio/uni-app";
// 计算属性与监听属性是在vue中而非uniap中 需要注意!!!
import {reactive ,toRefs,ref,computed ,getCurrentInstance }from "vue";
import { onLoad, onReady } from "@dcloudio/uni-app";
import { reactive, toRefs, ref, getCurrentInstance } from "vue";
const birthdayShow = ref(false)
const title = ref("成员管理")
@@ -94,10 +98,39 @@ const showType = ref(false)
const sexList = ref([])
const showSex = ref(false)
// 错误字段
const errorFields = ref([])
// 输入框基础样式
const inputBaseStyle = {
background: '#ffffff',
border: '2rpx solid #dcdfe6',
borderRadius: '8rpx',
padding: '0 24rpx',
height: '68rpx',
width: '100%',
boxSizing: 'border-box'
}
// 输入框错误样式
const inputErrorStyle = {
background: '#fef0f0',
border: '2rpx solid #f56c6c',
borderRadius: '8rpx',
padding: '0 24rpx',
height: '68rpx',
width: '100%',
boxSizing: 'border-box'
}
// 根据字段名获取输入框样式
const getInputStyle = (field) => {
return errorFields.value.includes(field) ? inputErrorStyle : inputBaseStyle
}
const data = reactive({
form: {
id: null,
id: null,
form: {
id: null,
name: null,
type: null,
createBy: null,
@@ -113,131 +146,141 @@ form: {
sex: null,
identityCard: null,
ranking: 0
},
rules: {
name: [{ required: true, message: '姓名不能为空', trigger:['change', 'blur'] }],
nickName: [{ required: true, message: '昵称不能为空', trigger: ['change', 'blur'] }],
birthday: [{ required: true, message: '生日不能为空', trigger: ['change', 'blur'] }],
typeName: [{ required: true, message: '类型不能为空', trigger: ['change', 'blur'] }],
sexName: [{ required: true, message: '性别不能为空', trigger: ['change', 'blur'] }],
}
},
rules: {
name: [{ required: true, message: '姓名不能为空', trigger: ['change', 'blur'] }],
nickName: [{ required: true, message: '昵称不能为空', trigger: ['change', 'blur'] }],
birthday: [{ required: true, message: '生日不能为空', trigger: ['change', 'blur'] }],
typeName: [{ required: true, message: '类型不能为空', trigger: ['change', 'blur'] }],
sexName: [{ required: true, message: '性别不能为空', trigger: ['change', 'blur'] }],
}
})
const { form, rules} = toRefs(data)
const { form, rules } = toRefs(data)
onLoad((option) => {
form.value.id = option.id
if(form.value.id!=null){
title.value="成员管理-修改"
}else{
title.value="成员管理-新增"
}
getData()
})
onReady(() => {
// form.value.birthday = dayjs(new Date().getTime()).format("YYYY-MM-DD")
form.value.id = option.id
if (form.value.id != null) {
title.value = "成员管理-修改"
} else {
title.value = "成员管理-新增"
}
getData()
})
function dictStr(val, arr) {
let str = ''
arr.map(item => {
if (item.dictValue === val) {
str = item.dictLabel
}
})
return str
}
function getData() {
// 类型
getDicts('person_type').then(res => {
typeList.value =[res.data]
})
// 类型
getDicts('sys_user_sex').then(res => {
sexList.value =[res.data]
})
if(form.value.id!=null){
getPerson(form.value.id).then(res => {
form.value = res.data
// 类型
getDicts('person_type').then(result => {
form.value.typeName=dictStr(form.value.type, result.data)
})
// 类型
getDicts('sys_user_sex').then(result => {
form.value.sexName=dictStr(form.value.sex, result.data)
})
})
let str = ''
arr.map(item => {
if (item.dictValue === val) {
str = item.dictLabel
}
})
return str
}
function handleType() {
if (typeList.value[0].length === 0) {
proxy.$refs['uToast'].show({
message: '类型为空 ', type: 'warning'
})
} else {
showType.value = true
}
}
function handleTypeConfirm(e) {
form.value.typeName = e.value[0].dictLabel
form.value.type = e.value[0].dictValue
showType.value = false
function getData() {
// 类型
getDicts('person_type').then(res => {
typeList.value = [res.data]
})
// 性别
getDicts('sys_user_sex').then(res => {
sexList.value = [res.data]
})
if (form.value.id != null) {
getPerson(form.value.id).then(res => {
form.value = res.data
// 类型
getDicts('person_type').then(result => {
form.value.typeName = dictStr(form.value.type, result.data)
})
// 性别
getDicts('sys_user_sex').then(result => {
form.value.sexName = dictStr(form.value.sex, result.data)
})
})
}
function handleTypeCancel() {
showType.value = false
}
}
function handleSex() {
if (sexList.value[0].length === 0) {
proxy.$refs['uToast'].show({
message: '性别为空 ', type: 'warning'
})
} else {
showSex.value = true
}
}
function handleSexConfirm(e) {
form.value.sexName = e.value[0].dictLabel
form.value.sex = e.value[0].dictValue
showSex.value = false
function handleType() {
if (typeList.value[0].length === 0) {
proxy.$refs['uToast'].show({
message: '类型为空 ', type: 'warning'
})
} else {
showType.value = true
}
function handleSexCancel() {
showSex.value = false
}
}
function selectBirthday() {
birthdayShow.value = true
proxy.$refs['birthdayRef'].innerValue = new Date().getTime()
function handleTypeConfirm(e) {
form.value.typeName = e.value[0].dictLabel
form.value.type = e.value[0].dictValue
showType.value = false
}
function handleTypeCancel() {
showType.value = false
}
function handleSex() {
if (sexList.value[0].length === 0) {
proxy.$refs['uToast'].show({
message: '性别为空 ', type: 'warning'
})
} else {
showSex.value = true
}
}
function handleSexConfirm(e) {
form.value.sexName = e.value[0].dictLabel
form.value.sex = e.value[0].dictValue
showSex.value = false
}
function handleSexCancel() {
showSex.value = false
}
function selectBirthday() {
birthdayShow.value = true
proxy.$refs['birthdayRef'].innerValue = new Date().getTime()
}
function birthdayConfirm(e) {
form.value.birthday = dayjs(e.value).format("YYYY-MM-DD")
birthdayShow.value = false
}
form.value.birthday = dayjs(e.value).format("YYYY-MM-DD")
birthdayShow.value = false
}
function submit() {
proxy.$refs['uForm'].validate().then(() => {
if (form.value.id != null) {
updatePerson(form.value).then(res => {
proxy.$refs['uToast'].show({
message: '修改成功', complete() {
uni.navigateTo({ url: `/pages/health/person/list` })
}
})
// 清空错误字段
errorFields.value = []
proxy.$refs['uForm'].validate().then(() => {
if (form.value.id != null) {
updatePerson(form.value).then(res => {
proxy.$refs['uToast'].show({
message: '修改成功', complete() {
uni.navigateTo({ url: `/pages/health/person/list` })
}
})
}else {
addPerson(form.value).then(res => {
proxy.$refs['uToast'].show({
message: '新增成功', complete() {
uni.navigateTo({ url: `/pages/health/person/list` })
}
})
})
} else {
addPerson(form.value).then(res => {
proxy.$refs['uToast'].show({
message: '新增成功', complete() {
uni.navigateTo({ url: `/pages/health/person/list` })
}
})
}
})
}
}).catch(errors => {
// 验证失败,记录错误字段
if (errors && errors.length > 0) {
errorFields.value = errors.map(err => err.field)
}
proxy.$modal.msgError('请填写完整信息')
})
}
</script>
<style lang="scss" scoped>
@@ -258,7 +301,7 @@ function submit() {
font-weight: 600;
display: flex;
align-items: center;
&::before {
content: '';
width: 6rpx;
@@ -275,6 +318,23 @@ function submit() {
.form-btn {
padding-top: 16rpx;
}
// 带箭头的输入框容器
.input-with-arrow {
position: relative;
width: 100%;
.arrow-icon {
position: absolute;
right: 20rpx;
top: 50%;
transform: translateY(-50%);
color: #c0c4cc;
font-size: 20rpx;
pointer-events: none;
z-index: 10;
}
}
}
}
</style>
@@ -293,4 +353,19 @@ function submit() {
font-weight: 500 !important;
letter-spacing: 2rpx !important;
}
</style>
/* 强制让错误状态的输入框边框变红 */
.u-form-item--error .u--input,
.u-form-item--error .u-input,
.u-form-item--error .u-input__content,
.u-form-item--error .u-input__content__field-wrapper {
border: 2rpx solid #f56c6c !important;
background: #fef0f0 !important;
}
.u-form-item--error .u--textarea,
.u-form-item--error .u-textarea {
border: 2rpx solid #f56c6c !important;
background: #fef0f0 !important;
}
</style>