feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Aurora Admin · PlateInput</title>
|
||||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||||
<link rel="stylesheet" href="./PlateInput.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="aa-page">
|
||||
<h2 class="aa-h2">PlateInput 车牌号输入</h2>
|
||||
<p class="aa-desc">省份简称 + 字母数字组合,自动大写,支持新能源车牌(7 位)。</p>
|
||||
|
||||
<div class="aa-demo">
|
||||
<div class="aa-demo__title">基础用法</div>
|
||||
<div class="aa-plate" id="plate">
|
||||
<div class="aa-plate-field" id="field">
|
||||
<select class="aa-plate-prov" id="prov">
|
||||
<option>京</option><option>沪</option><option>粤</option>
|
||||
<option>津</option><option>冀</option><option>鲁</option><option>苏</option>
|
||||
</select>
|
||||
<input class="aa-plate-input" role="group" id="input" placeholder="A12345" maxlength="7" />
|
||||
</div>
|
||||
<div class="aa-plate-tip" id="tip"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var PROV = '京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领';
|
||||
var field = document.getElementById('field');
|
||||
var prov = document.getElementById('prov');
|
||||
var input = document.getElementById('input');
|
||||
var tip = document.getElementById('tip');
|
||||
|
||||
function validate(prov, body) {
|
||||
if (!body) return { state: 'empty' };
|
||||
// 新能源:省+1字母+6位,共 8;标准:省+1字母+5位,共 7
|
||||
if (/^[A-Z][A-Z0-9]{6}$/.test(body)) return { state: 'valid', newEnergy: true };
|
||||
if (/^[A-Z][A-Z0-9]{5}$/.test(body)) return { state: 'valid', newEnergy: false };
|
||||
return { state: 'invalid' };
|
||||
}
|
||||
|
||||
function render() {
|
||||
var body = input.value.toUpperCase();
|
||||
var r = validate(prov.value, body);
|
||||
field.classList.remove('is-valid', 'is-invalid');
|
||||
tip.className = 'aa-plate-tip';
|
||||
if (r.state === 'empty') { tip.textContent = '格式:省份 + 字母 + 5/6 位(新能源 6 位)'; }
|
||||
else if (r.state === 'valid') {
|
||||
field.classList.add('is-valid'); tip.className = 'aa-plate-tip valid';
|
||||
tip.innerHTML = '车牌号合法:' + prov.value + body + '<span class="aa-plate-tag">' + (r.newEnergy ? '新能源' : '普通') + '</span>';
|
||||
} else {
|
||||
field.classList.add('is-invalid'); tip.className = 'aa-plate-tip invalid';
|
||||
tip.textContent = '车牌格式不正确(首位应为字母)';
|
||||
}
|
||||
}
|
||||
input.addEventListener('input', function () { input.value = input.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 7); render(); });
|
||||
prov.addEventListener('change', render);
|
||||
input.addEventListener('focus', function () { field.classList.add('is-focus'); });
|
||||
input.addEventListener('blur', function () { field.classList.remove('is-focus'); });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import './PlateInput.css';
|
||||
|
||||
export default function PlateInput({
|
||||
modelValue = '',
|
||||
provinces = ['京', '沪', '粤', '津', '冀', '鲁', '苏', '浙', '川', '渝'],
|
||||
onChange
|
||||
}) {
|
||||
const [prov, setProv] = useState(modelValue ? modelValue[0] : '京');
|
||||
const [body, setBody] = useState(modelValue ? modelValue.slice(1) : '');
|
||||
const [focused, setFocused] = useState(false);
|
||||
|
||||
const valid = /^[A-Z][A-Z0-9]{5}$/.test(body) || /^[A-Z][A-Z0-9]{6}$/.test(body);
|
||||
const invalid = !!body && !valid;
|
||||
const isNewEnergy = /^[A-Z][A-Z0-9]{6}$/.test(body);
|
||||
const tipClass = !body ? '' : valid ? 'valid' : 'invalid';
|
||||
const tipText = !body
|
||||
? '格式:省份 + 字母 + 5/6 位(新能源 6 位)'
|
||||
: valid
|
||||
? '车牌号合法:' + prov + body + '<span class="aa-plate-tag">' + (isNewEnergy ? '新能源' : '普通') + '</span>'
|
||||
: '车牌格式不正确(首位应为字母)';
|
||||
|
||||
const onInput = (e) => {
|
||||
const v = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 7);
|
||||
e.target.value = v;
|
||||
setBody(v);
|
||||
if (onChange) onChange(prov + v);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="aa-plate">
|
||||
<div
|
||||
className={'aa-plate-field' + (focused ? ' is-focus' : '') + (valid ? ' is-valid' : '') + (invalid ? ' is-invalid' : '')}
|
||||
>
|
||||
<select className="aa-plate-prov" value={prov} onChange={(e) => setProv(e.target.value)}>
|
||||
{provinces.map((p) => (
|
||||
<option key={p} value={p}>
|
||||
{p}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
className="aa-plate-input"
|
||||
value={body}
|
||||
maxLength={7}
|
||||
placeholder="A12345"
|
||||
onInput={onInput}
|
||||
onFocus={() => setFocused(true)}
|
||||
onBlur={() => setFocused(false)}
|
||||
/>
|
||||
</div>
|
||||
<div className={'aa-plate-tip ' + tipClass} dangerouslySetInnerHTML={{ __html: tipText }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<div class="aa-plate">
|
||||
<div class="aa-plate-field" :class="{ 'is-focus': focused, 'is-valid': valid, 'is-invalid': invalid }">
|
||||
<select class="aa-plate-prov" v-model="prov">
|
||||
<option v-for="p in provinces" :key="p" :value="p">{{ p }}</option>
|
||||
</select>
|
||||
<input
|
||||
class="aa-plate-input"
|
||||
:value="body"
|
||||
maxlength="7"
|
||||
placeholder="A12345"
|
||||
@input="onInput"
|
||||
@focus="focused = true"
|
||||
@blur="focused = false"
|
||||
/>
|
||||
</div>
|
||||
<div class="aa-plate-tip" :class="tipClass" v-html="tipText"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AaPlateInput',
|
||||
props: {
|
||||
value: { type: String, default: '' },
|
||||
provinces: { type: Array, default: () => ['京', '沪', '粤', '津', '冀', '鲁', '苏', '浙', '川', '渝'] }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
prov: this.value ? this.value[0] : '京',
|
||||
body: this.value ? this.value.slice(1) : '',
|
||||
focused: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
valid() {
|
||||
return /^[A-Z][A-Z0-9]{5}$/.test(this.body) || /^[A-Z][A-Z0-9]{6}$/.test(this.body);
|
||||
},
|
||||
invalid() {
|
||||
return !!this.body && !this.valid;
|
||||
},
|
||||
isNewEnergy() {
|
||||
return /^[A-Z][A-Z0-9]{6}$/.test(this.body);
|
||||
},
|
||||
tipClass() {
|
||||
if (!this.body) return '';
|
||||
return this.valid ? 'valid' : 'invalid';
|
||||
},
|
||||
tipText() {
|
||||
if (!this.body) return '格式:省份 + 字母 + 5/6 位(新能源 6 位)';
|
||||
if (this.valid) return '车牌号合法:' + this.prov + this.body + '<span class="aa-plate-tag">' + (this.isNewEnergy ? '新能源' : '普通') + '</span>';
|
||||
return '车牌格式不正确(首位应为字母)';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onInput(e) {
|
||||
this.body = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 7);
|
||||
e.target.value = this.body;
|
||||
this.$emit('input', this.prov + this.body);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="./PlateInput.css"></style>
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<div class="aa-plate">
|
||||
<div class="aa-plate-field" :class="{ 'is-focus': focused, 'is-valid': valid, 'is-invalid': invalid }">
|
||||
<select class="aa-plate-prov" v-model="prov">
|
||||
<option v-for="p in provinces" :key="p" :value="p">{{ p }}</option>
|
||||
</select>
|
||||
<input
|
||||
class="aa-plate-input"
|
||||
:value="body"
|
||||
maxlength="7"
|
||||
placeholder="A12345"
|
||||
@input="onInput"
|
||||
@focus="focused = true"
|
||||
@blur="focused = false"
|
||||
/>
|
||||
</div>
|
||||
<div class="aa-plate-tip" :class="tipClass" v-html="tipText"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: { type: String, default: '' },
|
||||
provinces: { type: Array, default: () => ['京', '沪', '粤', '津', '冀', '鲁', '苏', '浙', '川', '渝'] }
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
const prov = ref(props.modelValue ? props.modelValue[0] : '京');
|
||||
const body = ref(props.modelValue ? props.modelValue.slice(1) : '');
|
||||
const focused = ref(false);
|
||||
|
||||
const valid = computed(() => /^[A-Z][A-Z0-9]{5}$/.test(body.value) || /^[A-Z][A-Z0-9]{6}$/.test(body.value));
|
||||
const invalid = computed(() => !!body.value && !valid.value);
|
||||
const isNewEnergy = computed(() => /^[A-Z][A-Z0-9]{6}$/.test(body.value));
|
||||
const tipClass = computed(() => (!body.value ? '' : valid.value ? 'valid' : 'invalid'));
|
||||
const tipText = computed(() => {
|
||||
if (!body.value) return '格式:省份 + 字母 + 5/6 位(新能源 6 位)';
|
||||
if (valid.value) return '车牌号合法:' + prov.value + body.value + '<span class="aa-plate-tag">' + (isNewEnergy.value ? '新能源' : '普通') + '</span>';
|
||||
return '车牌格式不正确(首位应为字母)';
|
||||
});
|
||||
|
||||
function onInput(e) {
|
||||
body.value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 7);
|
||||
e.target.value = body.value;
|
||||
emit('update:modelValue', prov.value + body.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="./PlateInput.css"></style>
|
||||
Reference in New Issue
Block a user