fix: 功能完善修改。

This commit is contained in:
tianyongbao
2026-06-28 13:47:31 +08:00
parent 33d54a26b3
commit c75048086b
2 changed files with 458 additions and 117 deletions

View File

@@ -1,129 +1,23 @@
/**
* uView u-input 组件补丁
* 在 isSelectLikereadonly/disabled模式下用 view 代替原生 input 显示文字
* 使下拉选择框超长文字可自动换行完整显示
*
* 通过 package.json 的 postinstall 自动执行
* 直接用预存的补丁文件覆盖原始文件
* 使下拉选择框readonly/disabled超长文字可自动换行完整显示
*/
const fs = require('fs');
const path = require('path');
const filePath = path.join('node_modules', 'uview-plus', 'components', 'u-input', 'u-input.vue');
const target = path.join('node_modules', 'uview-plus', 'components', 'u-input', 'u-input.vue');
const source = path.join('scripts', 'u-input.vue');
if (!fs.existsSync(filePath)) {
console.log('[patch-u-input] u-input.vue not found, skipping');
if (!fs.existsSync(target)) {
console.log('[patch-u-input] target not found, skipping');
process.exit(0);
}
let content = fs.readFileSync(filePath, 'utf8');
let patched = false;
// === 补丁1模板中添加 v-if/v-else ===
if (!content.includes('u-input__content__field-wrapper__field--selectlike')) {
const oldTemplate = ` <input
class="u-input__content__field-wrapper__field"
:style="[inputStyle]"
:type="type"`;
const newTemplate = ` <!-- 选择型readonly/disabled用 view 显示文字,支持自动换行 -->
<view
v-if="isSelectLike"
class="u-input__content__field-wrapper__field u-input__content__field-wrapper__field--selectlike"
:style="[inputStyle]"
>
<text v-if="innerValue" class="u-input__content__field-wrapper__field__text">{{ innerValue }}</text>
<text v-else class="u-input__content__field-wrapper__field__placeholder">{{ placeholder }}</text>
</view>
<!-- 普通输入模式保持原生 input -->
<input
v-else
class="u-input__content__field-wrapper__field"
:style="[inputStyle]"
:type="type"`;
if (content.includes(oldTemplate)) {
content = content.replace(oldTemplate, newTemplate);
patched = true;
}
if (!fs.existsSync(source)) {
console.log('[patch-u-input] source not found, skipping');
process.exit(0);
}
// === 补丁2CSS - 修改 .u-input--selectlike 块,添加高度自适应 ===
if (patched && content.includes('&--selectlike {\n .u-input__content,')) {
const oldSelectlike = ` &--selectlike {
.u-input__content,
.u-input__content__field-wrapper,
.u-input__content__field-wrapper__field {
pointer-events: none;
}
}`;
const newSelectlike = ` &--selectlike {
height: auto !important;
min-height: 68rpx;
.u-input__content,
.u-input__content__field-wrapper,
.u-input__content__field-wrapper__field {
pointer-events: none;
}
}`;
if (content.includes(oldSelectlike)) {
content = content.replace(oldSelectlike, newSelectlike);
}
}
// === 补丁3CSS - 在 &__field 中添加 selectlike 子样式 ===
if (patched && !content.includes('&__text {')) {
const oldField = ` &__field {
line-height: 26px;
text-align: left;
color: $u-main-color;
height: 24px;
font-size: 15px;
flex: 1;
}
}`;
const newField = ` &__field {
line-height: 26px;
text-align: left;
color: $u-main-color;
height: 24px;
font-size: 15px;
flex: 1;
&--selectlike {
min-height: 24px;
height: auto !important;
line-height: 26px;
word-break: break-all;
white-space: normal;
width: 100%;
}
&__text {
color: $u-main-color;
font-size: 15px;
line-height: 26px;
}
&__placeholder {
color: $u-light-color;
font-size: 15px;
line-height: 26px;
}
}
}`;
if (content.includes(oldField)) {
content = content.replace(oldField, newField);
}
}
if (patched) {
fs.writeFileSync(filePath, content, 'utf8');
console.log('[patch-u-input] Patched successfully');
} else {
console.log('[patch-u-input] Already patched or pattern not found, skipping');
}
fs.copyFileSync(source, target);
console.log('[patch-u-input] Patched successfully');