7/30 限制前端输入字数

This commit is contained in:
Zy
2026-07-30 17:59:32 +08:00
parent 903c92fef0
commit 2907f9202c
115 changed files with 2561 additions and 1213 deletions

View File

@@ -382,6 +382,9 @@ onUnmounted(() => {
}
</style>
<style scoped>
.editor {
max-width: 800px;
}
.editor,
.ql-toolbar {
white-space: pre-wrap !important;

View File

@@ -1,6 +1,26 @@
<template>
<slot name="default" />
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
<nav class="flex flex-items-center mb-8 justify-between">
<div class="flex flex-items-center">
<div class="flex flex-items-center mr-20px">
<div style="width: 80px; text-align: right; padding-right: 10px">业主账号</div>
<div class="flex-1">
<el-input clearable @clear="handleClear" style="width: 200px" v-model="queryParams.userName" placeholder="请输入业主账号"></el-input>
</div>
</div>
<div class="flex flex-items-center mr-20px">
<div style="width: 60px; text-align: right; padding-right: 10px">手机号</div>
<div class="flex-1">
<el-input clearable @clear="handleClear" style="width: 200px" v-model="queryParams.userPhone" placeholder="请输入手机号"></el-input>
</div>
</div>
</div>
<div>
<el-button type="primary" @click="getList">查询</el-button>
<el-button @click="resetQuery">重置</el-button>
</div>
</nav>
<el-table v-loading="loading" ref="multipleTableRef" :data="tableData" border @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="业主" align="center">
@@ -64,7 +84,9 @@ const dialog = ref({
const queryParams = ref({
pageNum: 1,
pageSize: 10
pageSize: 10,
userPhone: '',
userName: ''
});
const multipleTableRef = ref();
@@ -101,7 +123,10 @@ const handleUserSelection = () => {
};
// ====================== 方法 ======================
function handleClear() {
queryParams.value.userName = '';
getList();
}
// 获取列表
function getList() {
isFetching.value = true; // 加锁
@@ -164,7 +189,9 @@ function handleSelectionChange(selection: AppUserList[]) {
function resetQuery() {
queryParams.value = {
pageNum: 1,
pageSize: 10
pageSize: 10,
userPhone: '',
userName: ''
};
getList();
}

View File

@@ -101,10 +101,6 @@ import { BillHouse, listBillHouse } from '@/api/system/SdbBill';
import { ref, nextTick, toRefs } from 'vue';
import pagination from '@/components/Pagination/index.vue';
// const { proxy } = getCurrentInstance() as ComponentInternalInstance;
// const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
// const { com_build_use } = toRefs<any>(proxy?.useDict('com_build_use'));
const props = defineProps({
returnvalue: {
type: String,

View File

@@ -11,7 +11,7 @@
</div>
</div>
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
<el-dialog @close="conback" append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
<nav class="flex flex-items-center mb-8">
<div class="flex flex-items-center mr-5 flex-1">
<div style="width: 120px">住户类型</div>
@@ -20,7 +20,7 @@
</el-select>
</div>
<div class="mr-5 flex-1">
<el-input clearable v-model="queryParams.name" placeholder="请输入住户姓名" />
<el-input maxlength="30" clearable v-model="queryParams.name" placeholder="请输入住户姓名" />
</div>
<div>
<el-button type="primary" @click="getlist">查询</el-button>

View File

@@ -40,14 +40,20 @@
</template>
</el-table-column>
<el-table-column label="角色" align="center" prop="roleName" />
<el-table-column label="当前任务数量" align="center" prop="taskCount" v-if="props.userType == 'repair'" />
<el-table-column label="手机号码" align="center" prop="phonenumber" />
<el-table-column label="状态" align="center" prop="status">
<template #default="{ row }">
<el-tag :type="row.status === '0' ? 'success' : 'danger'">{{ row.status === '0' ? '正常' : '停用' }}</el-tag>
</template>
</el-table-column>
</el-table>
<template #footer>
<div class="dialog-footer flex flex-items-center flex-justify-between">
<pagination
style="margin-top: 0"
layout="total, prev, pager, next, jumper"
layout="total, sizes, prev, pager, next, jumper"
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
@@ -180,7 +186,10 @@ function choiceResidentFun() {
// 获取列表
function getList() {
loading.value = true;
getUserByRoleKey(userType.value)
getUserByRoleKey({
...queryParams.value,
roleKey: userType.value
})
.then((res) => {
tableData.value = res.rows;
total.value = res.total;

View File

@@ -1,9 +1,59 @@
<template>
<slot name="default" />
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
<nav class="flex flex-items-center mb-8 justify-between">
<div class="flex flex-items-center">
<div class="flex flex-items-center">
<div style="width: 50px; text-align: right; padding-right: 10px">楼栋</div>
<div class="flex-1"></div>
<el-select @change="handleChangeBuilding" clearable style="width: 120px" v-model="queryParams.buildingId">
<el-option v-for="(item, index) in buildingList" :key="index" :label="item.buildingName" :value="item.id"></el-option>
</el-select>
</div>
<div class="flex flex-items-center mr-20px">
<div style="width: 50px; text-align: right; padding-right: 10px">单元</div>
<div class="flex-1">
<el-select @change="handleChangeUnit" clearable style="width: 120px" v-model="queryParams.unitNoId">
<el-option v-for="(item, index) in unitList" :key="index" :label="item.unitNoName" :value="item.unitNoId"></el-option>
</el-select>
</div>
</div>
<div class="flex flex-items-center mr-20px">
<div style="width: 60px; text-align: right; padding-right: 10px">房屋号</div>
<div class="flex-1">
<el-input clearable @clear="handleClear" style="width: 120px" v-model="queryParams.houseNo" placeholder="请输入房屋号"></el-input>
</div>
</div>
<div class="flex flex-items-center mr-20px">
<div style="width: 80px; text-align: right; padding-right: 10px">业主名称</div>
<div class="flex-1">
<el-input clearable @clear="handleClear" style="width: 120px" v-model="queryParams.residentName" placeholder="请输入业主名称"></el-input>
</div>
</div>
</div>
<div>
<el-button type="primary" @click="getList">查询</el-button>
<el-button @click="resetQuery">重置</el-button>
</div>
</nav>
<el-table ref="multipleTableRef" :data="tableData" border @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="序号" align="center" width="55" type="index" />
<el-table-column label="楼栋号" align="center">
<template #default="scope">
<span>{{ scope.row.house_name ? scope.row.house_name.split('-')[0] : '---' }}</span>
</template>
</el-table-column>
<el-table-column label="单元" align="center">
<template #default="scope">
<span>{{ scope.row.house_name ? scope.row.house_name.split('-')[1] : '---' }}</span>
</template>
</el-table-column>
<el-table-column label="房间" align="center">
<template #default="scope">
<span>{{ scope.row.house_name ? scope.row.house_name.split('-')[2] : '---' }}</span>
</template>
</el-table-column>
<el-table-column label="业主" align="center">
<template #default="scope">
<span>{{ scope.row.residentName ? scope.row.residentName : '---' }}</span>
@@ -15,9 +65,7 @@
</template>
</el-table-column>
<el-table-column label="手机号" align="center" prop="phone" />
<el-table-column label="房屋" align="center" prop="house_name" />
</el-table>
<template #footer>
<div class="dialog-footer flex flex-items-center flex-justify-between">
<pagination
@@ -27,7 +75,7 @@
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getlist"
@pagination="getList"
/>
<div>
<el-button @click="conback">退出</el-button>
@@ -77,7 +125,12 @@ const dialog = ref({
const queryParams = ref({
pageNum: 1,
pageSize: 10
pageSize: 10,
buildingId: null,
residentName: null,
houseNo: null,
unitNoId: null
});
const multipleTableRef = ref();
@@ -116,7 +169,7 @@ const handleUserSelection = () => {
// ====================== 方法 ======================
// 获取列表
function getlist() {
function getList() {
isFetching.value = true; // 加锁
loading.value = true;
queryResidentList_holder(queryParams.value)
@@ -135,23 +188,33 @@ function getlist() {
}
/** 楼栋列表 */
const buildinglist = ref([]);
/** 房屋列表 */
const unitlist = ref([]);
/** 筛选房屋类型 */
function handleChangeHouse(val: string) {
const buildingList = ref([]);
/** 单元列表 */
const unitList = ref([]);
/** 获取楼栋 列表 */
function handleChangeHouse() {
getBuildinglistAPI().then((res) => {
buildinglist.value = res.data;
buildingList.value = res.data;
});
}
function handleClear() {
getList();
}
/** 单元列表 */
function handleChangebuilding(val: string) {
getHouselistAPI(val).then((res) => {
unitlist.value = res.data.units;
});
function handleChangeBuilding(val: string) {
queryParams.value.unitNoId = null;
unitList.value = [];
if (queryParams.value.buildingId) {
getHouselistAPI(val).then((res) => {
unitList.value = res.data.units;
getList();
});
}
getList();
}
function handleChangeUnit() {
getList();
}
// ==============================================
// ✅ 新增:处理 selection-change(多选专用)
// ==============================================
@@ -183,39 +246,17 @@ function handleSelectionChange(selection: BillUserlist[]) {
}
}
}
// ==============================================
// 最佳单选方案:点击行选中,无报错、无循环、最稳定
// ==============================================
// 优化 handleRowClick,避免重复
function handleRowClick(row: BillUserlist) {
if (!multipleTableRef.value) return;
if (isMultiple.value) {
const index = multipleSelection.value.findIndex((item) => item.residentId === row.residentId);
if (index > -1) {
// 取消选中
multipleSelection.value.splice(index, 1);
multipleTableRef.value?.toggleRowSelection(row, false);
} else {
// 选中
multipleSelection.value.push(row);
multipleTableRef.value?.toggleRowSelection(row, true);
}
} else {
// 【单选模式】先清空,再选中当前行
multipleSelection.value = [];
multipleTableRef.value.clearSelection();
multipleSelection.value = [row];
multipleTableRef.value.toggleRowSelection(row, true);
}
}
// 重置查询
function resetQuery() {
queryParams.value = {
pageNum: 1,
pageSize: 10
pageSize: 10,
buildingId: null,
unitNoId: null,
residentName: null,
houseNo: null
};
getlist();
getList();
}
// 退出
@@ -270,7 +311,8 @@ defineExpose({
multipleSelection.value = [];
}
getlist();
getList();
handleChangeHouse();
dialog.value.dialogVisible = true;
}
});

View File

@@ -1,359 +0,0 @@
<template>
<div class="license-plate-input">
<div class="plate_line">
<div
v-for="(item, index) in chars"
:key="index"
class="plate-item"
:class="{
active: activeIndex === index,
disabled: disabled,
error: hasError
}"
>
<input
ref="inputRefs"
v-model="chars[index]"
type="text"
maxlength="1"
:disabled="disabled"
@input="onInput(index)"
@keydown="onKeydown($event, index)"
@paste="onPaste"
@focus="activeIndex = index"
@blur="onBlur"
@compositionend="onCompositionEnd(index)"
/>
</div>
</div>
<!-- 错误提示 -->
<transition name="el-fade-in-linear">
<div v-if="hasError && errorMessage" class="plate-error">
{{ errorMessage }}
</div>
</transition>
</div>
</template>
<script setup lang="ts">
import { ref, watch, nextTick } from 'vue';
import { LicensePlateValidator } from '@/utils/Reg';
// 省份简称
const PROVINCES = [
'京',
'津',
'沪',
'渝',
'冀',
'豫',
'云',
'辽',
'黑',
'湘',
'皖',
'鲁',
'新',
'苏',
'浙',
'赣',
'鄂',
'桂',
'甘',
'晋',
'蒙',
'陕',
'吉',
'闽',
'贵',
'粤',
'青',
'藏',
'川',
'宁',
'琼'
];
// 合法基础字符:字母 (排除I,O) 和 数字
const VALID_CHAR_REGEX = /^[A-HJ-NP-Z0-9]$/i;
// 车牌特殊结尾字符
const SPECIAL_CHARS = ['警', '学', '挂', '临', '超', '港', '澳'];
const props = defineProps<{
modelValue: string;
disabled?: boolean;
required?: boolean;
}>();
const emit = defineEmits<{
'update:modelValue': [value: string];
'change': [value: string];
}>();
const inputRefs = ref<HTMLInputElement[]>([]);
const activeIndex = ref(-1);
const chars = ref<string[]>(Array(8).fill(''));
const hasError = ref(false);
const errorMessage = ref('');
// 外部值同步到内部
watch(
() => props.modelValue,
(val) => {
const cleanVal = (val || '').toUpperCase().trim();
const currentJoined = chars.value.join('').trim();
if (cleanVal !== currentJoined) {
const newChars = Array(8).fill('');
if (cleanVal) {
const arr = cleanVal.split('');
for (let i = 0; i < Math.min(arr.length, 8); i++) {
newChars[i] = arr[i];
}
}
chars.value = newChars;
if (cleanVal) clearError();
}
},
{ immediate: true }
);
// 内部值同步到外部
watch(
chars,
(newChars) => {
const value = newChars.join('').trim();
emit('update:modelValue', value);
emit('change', value);
if (hasError.value) {
clearError();
}
},
{ deep: true }
);
function onInput(index: number) {
let char = chars.value[index];
if (!char) return;
// 统一转大写 (汉字不受影响)
char = char.toUpperCase();
let isValid = false;
// 1. 第一位:必须是省份
if (index === 0) {
if (PROVINCES.includes(char)) {
isValid = true;
}
}
// 2. 特殊字符处理 (警/学/挂/临/超/港/澳)
else if (SPECIAL_CHARS.includes(char)) {
// 特殊字符通常出现在最后一位,或者倒数第二位(如临时车牌的"临"可能在最后,也可能在倒数第二?不,通常是最后)
// 为了用户体验,允许在任何非第一位的位置输入,但最终校验会判断位置是否正确
isValid = true;
}
// 3. 常规字符:字母或数字
else {
if (VALID_CHAR_REGEX.test(char)) {
isValid = true;
}
}
if (!isValid) {
chars.value[index] = '';
return;
} else {
chars.value[index] = char;
// 如果输入的是特殊字符,通常意味着车牌结束,不再自动跳转
// 如果输入的是常规字符,且不是最后一格,则跳转
if (!SPECIAL_CHARS.includes(char) && char && index < 7) {
nextTick(() => {
inputRefs.value[index + 1]?.focus();
});
}
}
}
function onCompositionEnd(index: number) {
onInput(index);
}
function onKeydown(e: KeyboardEvent, index: number) {
if (e.key === 'Backspace') {
if (!chars.value[index] && index > 0) {
e.preventDefault();
nextTick(() => {
inputRefs.value[index - 1]?.focus();
});
}
return;
}
if (e.key === 'ArrowLeft' && index > 0) {
e.preventDefault();
inputRefs.value[index - 1]?.focus();
}
if (e.key === 'ArrowRight' && index < 7) {
e.preventDefault();
inputRefs.value[index + 1]?.focus();
}
}
function onPaste(e: ClipboardEvent) {
e.preventDefault();
const text = e.clipboardData?.getData('text')?.toUpperCase().trim() || '';
if (!text) return;
const filledChars = [...chars.value];
let insertPos = activeIndex.value >= 0 ? activeIndex.value : 0;
for (let i = 0; i < text.length; i++) {
if (insertPos >= 8) break;
const char = text[i];
let canInsert = false;
if (insertPos === 0) {
if (PROVINCES.includes(char)) canInsert = true;
} else if (SPECIAL_CHARS.includes(char)) {
canInsert = true;
} else {
if (VALID_CHAR_REGEX.test(char)) canInsert = true;
}
if (canInsert) {
filledChars[insertPos] = char;
insertPos++;
}
}
chars.value = filledChars;
nextTick(() => {
const focusIdx = Math.min(insertPos, 7);
inputRefs.value[focusIdx]?.focus();
});
}
function onBlur() {
setTimeout(() => {
const hasFocus = inputRefs.value.some((input) => document.activeElement === input);
if (!hasFocus) {
activeIndex.value = -1;
validate();
}
}, 200);
}
function validate(): { valid: boolean; message?: string } {
const value = chars.value.join('').trim();
if (props.required && !value) {
setError('请输入车牌号');
return { valid: false, message: '请输入车牌号' };
}
if (!value) {
clearError();
return { valid: true };
}
if (!LicensePlateValidator.isValidPlate(value)) {
setError('车牌号格式不正确');
return { valid: false, message: '车牌号格式不正确' };
}
clearError();
return { valid: true };
}
function setError(msg: string) {
hasError.value = true;
errorMessage.value = msg;
}
function clearError() {
hasError.value = false;
errorMessage.value = '';
}
defineExpose({
focus: () => nextTick(() => inputRefs.value[0]?.focus()),
clear: () => {
chars.value = Array(8).fill('');
clearError();
emit('update:modelValue', '');
emit('change', '');
},
validate,
clearError
});
</script>
<style scoped>
.license-plate-input {
display: flex;
flex-direction: column;
gap: 4px;
width: fit-content;
}
.plate_line {
display: flex;
align-items: center;
gap: 6px;
}
.plate-item {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
background-color: #fff;
}
.plate-item.active {
border-color: #409eff;
box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}
.plate-item.error {
border-color: #f56c6c;
}
.plate-item.disabled {
background-color: #f5f7fa;
cursor: not-allowed;
color: #a8abb2;
}
.plate-item input {
width: 100%;
height: 100%;
border: none;
text-align: center;
font-size: 16px;
font-weight: 500;
background: transparent;
outline: none;
padding: 0;
margin: 0;
color: inherit;
}
.plate-error {
color: #f56c6c;
font-size: 12px;
line-height: 1.5;
margin-top: 2px;
min-height: 18px;
}
</style>

View File

@@ -52,7 +52,7 @@ import { CSSProperties } from 'vue';
const props = defineProps({
columns: propTypes.fieldOption,
gutter: propTypes.number.def(10),
moreTitle: propTypes.string.def('批量操作'),
moreTitle: propTypes.string.def('更多操作'),
showAdd: propTypes.bool.def(true),
showDelete: propTypes.bool.def(true),

View File

@@ -79,7 +79,7 @@ defineProps<{
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-size: 11px;
font-weight: 800;
flex-shrink: 0;
z-index: 1;