From a57f1d6b6d0327857c561da7143883c848fa8f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BE=B7=E4=BA=91?= Date: Sun, 16 Feb 2025 00:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=A6=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E7=9A=84=E8=BE=93=E5=85=A5=E6=A1=86=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=BD=AC=E6=8D=A2=E7=B2=BE=E5=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/system/sysUnitConvert.js | 44 ++ pages/index.vue | 125 +++-- uni_modules/yjly-inputunit/changelog.md | 6 + .../yjly-inputunit/yjly-inputunit.vue | 430 ++++++++++++++++++ .../components/yjly-inputunit/yjlyUnitData.js | 122 +++++ .../package.json | 50 +- uni_modules/yjly-inputunit/readme.md | 158 +++++++ uni_modules/yjly-number_unit/changelog.md | 0 .../yjly-number_unit/yjly-number_unit.vue | 272 ----------- uni_modules/yjly-number_unit/readme.md | 1 - 10 files changed, 869 insertions(+), 339 deletions(-) create mode 100644 api/system/sysUnitConvert.js create mode 100644 uni_modules/yjly-inputunit/changelog.md create mode 100644 uni_modules/yjly-inputunit/components/yjly-inputunit/yjly-inputunit.vue create mode 100644 uni_modules/yjly-inputunit/components/yjly-inputunit/yjlyUnitData.js rename uni_modules/{yjly-number_unit => yjly-inputunit}/package.json (50%) create mode 100644 uni_modules/yjly-inputunit/readme.md delete mode 100644 uni_modules/yjly-number_unit/changelog.md delete mode 100644 uni_modules/yjly-number_unit/components/yjly-number_unit/yjly-number_unit.vue delete mode 100644 uni_modules/yjly-number_unit/readme.md diff --git a/api/system/sysUnitConvert.js b/api/system/sysUnitConvert.js new file mode 100644 index 0000000..10f92d4 --- /dev/null +++ b/api/system/sysUnitConvert.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询单位换算列表 +export function listSysUnitConvert(query) { + return request({ + url: '/system/sysUnitConvert/list', + method: 'get', + params: query + }) +} + +// 查询单位换算详细 +export function getSysUnitConvert(id) { + return request({ + url: '/system/sysUnitConvert/' + id, + method: 'get' + }) +} + +// 新增单位换算 +export function addSysUnitConvert(data) { + return request({ + url: '/system/sysUnitConvert', + method: 'post', + data: data + }) +} + +// 修改单位换算 +export function updateSysUnitConvert(data) { + return request({ + url: '/system/sysUnitConvert', + method: 'put', + data: data + }) +} + +// 删除单位换算 +export function delSysUnitConvert(id) { + return request({ + url: '/system/sysUnitConvert/' + id, + method: 'delete' + }) +} diff --git a/pages/index.vue b/pages/index.vue index 63e6dce..705ff70 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,43 +1,84 @@ - - - - - diff --git a/uni_modules/yjly-inputunit/changelog.md b/uni_modules/yjly-inputunit/changelog.md new file mode 100644 index 0000000..865a324 --- /dev/null +++ b/uni_modules/yjly-inputunit/changelog.md @@ -0,0 +1,6 @@ +## 1.0.2(2025-02-19) +修改单位转换精度,将原始单位和值暂存,换算到基准单位值,再换算到新单位值。 +## 1.0.1(2025-02-15) +修改单位类型默认值 +## 1.0.0(2025-02-15) +1.0.0 diff --git a/uni_modules/yjly-inputunit/components/yjly-inputunit/yjly-inputunit.vue b/uni_modules/yjly-inputunit/components/yjly-inputunit/yjly-inputunit.vue new file mode 100644 index 0000000..3587446 --- /dev/null +++ b/uni_modules/yjly-inputunit/components/yjly-inputunit/yjly-inputunit.vue @@ -0,0 +1,430 @@ + + + + + diff --git a/uni_modules/yjly-inputunit/components/yjly-inputunit/yjlyUnitData.js b/uni_modules/yjly-inputunit/components/yjly-inputunit/yjlyUnitData.js new file mode 100644 index 0000000..63e4f0f --- /dev/null +++ b/uni_modules/yjly-inputunit/components/yjly-inputunit/yjlyUnitData.js @@ -0,0 +1,122 @@ +const unitData = { + pressure: [{ + + "id": 66, + "unitType": "pressure", + "unitName": "Pa(帕斯卡)", + "baseUnit": "Y", + "conversionFactor": 1, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 0 + }, + { + + "id": 67, + "unitType": "pressure", + "unitName": "kPa(千帕)", + "baseUnit": "N", + "conversionFactor": 0.001, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 1 + }, + { + + "id": 68, + "unitType": "pressure", + "unitName": "MPa(兆帕)", + "baseUnit": "N", + "conversionFactor": 0.000001, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 2 + }, + { + + "id": 69, + "unitType": "pressure", + "unitName": "atm(标准大气压)", + "baseUnit": "N", + "conversionFactor": 0.0000098692326671601, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 3 + }, + { + + "id": 70, + "unitType": "pressure", + "unitName": "bar(巴)", + "baseUnit": "N", + "conversionFactor": 0.00001, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 4 + }, + { + + "id": 71, + "unitType": "pressure", + "unitName": "mbar(毫巴)", + "baseUnit": "N", + "conversionFactor": 0.01, + "unitTypeName": "压力", + "status": "Y", + "unitOrder": 5 + } + ], + length: [{ + "id": 1, + "unitType": "length", + "unitName": "m(米)", + "baseUnit": "Y", + "conversionFactor": 1, + "unitTypeName": "长度", + "status": "Y", + "unitOrder": 0 + }, + { + "id": 2, + "unitType": "length", + "unitName": "dm(分米)", + "baseUnit": "N", + "conversionFactor": 10, + "unitTypeName": "长度", + "status": "Y", + "unitOrder": 1 + }, + { + "id": 3, + "unitType": "length", + "unitName": "cm(厘米)", + "baseUnit": "N", + "conversionFactor": 100, + "unitTypeName": "长度", + "status": "Y", + "unitOrder": 2 + }, + { + "id": 4, + "unitType": "length", + "unitName": "mm(毫米)", + "baseUnit": "N", + "conversionFactor": 1000, + "unitTypeName": "长度", + "status": "Y", + "unitOrder": 3 + }, + { + "id": 5, + "unitType": "length", + "unitName": "km(千米)", + "baseUnit": "N", + "conversionFactor": 0.001, + "unitTypeName": "长度", + "status": "Y", + "unitOrder": 4 + } + ] +} + +export default unitData; \ No newline at end of file diff --git a/uni_modules/yjly-number_unit/package.json b/uni_modules/yjly-inputunit/package.json similarity index 50% rename from uni_modules/yjly-number_unit/package.json rename to uni_modules/yjly-inputunit/package.json index 16b715f..c335879 100644 --- a/uni_modules/yjly-number_unit/package.json +++ b/uni_modules/yjly-inputunit/package.json @@ -1,14 +1,15 @@ { - "id": "yjly-number_unit", - "displayName": "yjly-number_unit", - "version": "1.0.0", - "description": "yjly-number_unit", + "id": "yjly-inputunit", + "displayName": "单位转换组件,双向数值绑定,单位循环切换、弹窗选择,支持自定义单位显示", + "version": "1.0.2", + "description": "单位转换组件 支持双向数值绑定 内置单位换算逻辑 支持单位循环切换/弹窗选择两种模式 兼容 Vue2/Vue3 和 UniApp 多平台 支持自定义单位显示 可配置小数位数精度", "keywords": [ - "yjly-number_unit" + "单位转换组件", + "双向数值绑定", + "自定义单位显示" ], "repository": "", - "engines": { - "HBuilderX": "^3.1.0" +"engines": { }, "dcloudext": { "type": "component-vue", @@ -24,9 +25,9 @@ "qq": "" }, "declaration": { - "ads": "", - "data": "", - "permissions": "" + "ads": "无", + "data": "无", + "permissions": "无" }, "npmurl": "" }, @@ -35,36 +36,37 @@ "encrypt": [], "platforms": { "cloud": { - "tcb": "u", - "aliyun": "u", - "alipay": "u" + "tcb": "y", + "aliyun": "y", + "alipay": "y" }, "client": { "Vue": { - "vue2": "u", - "vue3": "u" + "vue2": "y", + "vue3": "y" }, "App": { - "app-vue": "u", - "app-nvue": "u", - "app-uvue": "u" + "app-vue": "y", + "app-nvue": "u", + "app-uvue": "u", + "app-harmony": "u" }, "H5-mobile": { "Safari": "u", "Android Browser": "u", - "微信浏览器(Android)": "u", - "QQ浏览器(Android)": "u" + "微信浏览器(Android)": "y", + "QQ浏览器(Android)": "y" }, "H5-pc": { - "Chrome": "u", + "Chrome": "y", "IE": "u", - "Edge": "u", + "Edge": "y", "Firefox": "u", "Safari": "u" }, "小程序": { - "微信": "u", - "阿里": "u", + "微信": "y", + "阿里": "y", "百度": "u", "字节跳动": "u", "QQ": "u", diff --git a/uni_modules/yjly-inputunit/readme.md b/uni_modules/yjly-inputunit/readme.md new file mode 100644 index 0000000..3bf02d7 --- /dev/null +++ b/uni_modules/yjly-inputunit/readme.md @@ -0,0 +1,158 @@ +# yjyl-input-unit 单位转换组件使用说明 +功能特性 +支持双向数值绑定 +内置单位换算逻辑(含温度特殊处理) +支持单位循环切换/弹窗选择两种模式 +兼容 Vue2/Vue3 和 UniApp 多平台 +支持自定义单位显示 +可配置小数位数精度 + +符合uni-modules标准,直接使用 + + +Props 配置 +|属性名 |类型 |必填 |默认值 |说明 | +|:-: |:-: |:-: |:-: |:-: | +|unitType |String |是 |- |单位类型(例:'length', 'weight', 'temperature') | +|unitOrder |Number |否 |0 |当前单位序号(需配合 .sync 修饰符使用) | +|value |Number |是 |- |输入数值(使用 v-model 双向绑定) | +|showEnglishOnly |Boolean|否 |false |是否只显示英文单位(例:'kg' 代替 ' 千克 (kg)') | +|decimalPlaces |Number |否 |5 |小数位数(0 - 10) | +|width |Number |否 |180 |组件总宽度(px) | +|height |Number |否 |32 |组件高度(px) | +|enableConvert |Boolean|否 |true |是否允许单位转换 | +|userDefined |Boolean|否 |false |是否使用自定义单位 | +|userDefinedunitName|String |否 |'' |自定义单位显示名称(需 userDefined = true 生效) | + + +事件说明 +| 事件名称 | 说明 | 回调参数 | +| input | 数值变化时触发 | (newValue: number) | +| update:unitOrder | 单位序号变化时触发 | (newOrder: number) | +| conversion | 完成单位转换时触发 | { initialValue, newValue, oldUnit, newUnit, oldOrder, newOrder } 的 Object | +使用示例 +基本用法 +vue + + + + +禁用转换模式 + + +事件处理 +vue +复制 + + + + +API 需自己开发,按照下面的数据格式进行组织,参考unitData.js +组件依赖 listSysUnitConvert API 获取单位数据,需实现以下格式的接口: + +javascript +{ + rows: [ + { + id: 1, + unitType: 'length', + unitName: '米(m)', + conversionFactor: 1, + baseUnit: 'Y', + unitOrder: 0 + }, + // ...其他单位数据 + ] +} +样式调整 +可通过以下 CSS 类名自定义样式: + +.unit-converter - 组件容器 + +.input-field - 输入框 + +.unit-label - 单位标签 + +.unit-selector - 单位选择器 + +.unit-option - 单位选项 + +平台差异 + +小程序端使用 longpress 事件触发选择器(长按代替双击) + +H5 端自动适配点击事件 + +单位转换规则 + +温度单位需按约定顺序定义: + +javascript +复制 +[ + { unitOrder: 0, unitName: '℃' }, // 摄氏度 + { unitOrder: 1, unitName: '℉' }, // 华氏度 + { unitOrder: 2, unitName: 'K' } // 开尔文 +] +自定义单位时需确保与现有换算逻辑兼容 + +常见问题 +Q1: 单位选择器不显示 + +检查 enableConvert 是否为 true + +确认单位数据加载成功 + +查看控制台是否有 API 错误 + +Q2: 数值更新不及时 + +确保使用 v-model 进行双向绑定 + +检查小数位数配置是否符合预期 + +确认没有在父组件中覆盖转换后的值 + +Q3: 样式显示异常 + +检查是否父容器有冲突的布局样式 + +确认单位标签宽度计算正确(通过 updateInputWidth 方法) + +在小程序端添加 !important 覆盖默认样式 + diff --git a/uni_modules/yjly-number_unit/changelog.md b/uni_modules/yjly-number_unit/changelog.md deleted file mode 100644 index e69de29..0000000 diff --git a/uni_modules/yjly-number_unit/components/yjly-number_unit/yjly-number_unit.vue b/uni_modules/yjly-number_unit/components/yjly-number_unit/yjly-number_unit.vue deleted file mode 100644 index b8ceaea..0000000 --- a/uni_modules/yjly-number_unit/components/yjly-number_unit/yjly-number_unit.vue +++ /dev/null @@ -1,272 +0,0 @@ - - - - - diff --git a/uni_modules/yjly-number_unit/readme.md b/uni_modules/yjly-number_unit/readme.md deleted file mode 100644 index 4e03f32..0000000 --- a/uni_modules/yjly-number_unit/readme.md +++ /dev/null @@ -1 +0,0 @@ -# yjly-number_unit \ No newline at end of file