提交 2549b063 编写于 作者: B baiy 提交者: ninecents

#66 fix

上级 55d00e1e
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.7.3", "version": "1.7.4",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --port 8081", "serve": "vue-cli-service serve --port 8081",
......
...@@ -3,9 +3,9 @@ const TOOL_DATA_EXPIRY = 3600 * 24 ...@@ -3,9 +3,9 @@ const TOOL_DATA_EXPIRY = 3600 * 24
// 徽章过期时间(天) // 徽章过期时间(天)
const BADGE_EXPIRY = 5 const BADGE_EXPIRY = 5
// 分类徽章 // 分类徽章
const BADGE_CATEGORY = ['other'] const BADGE_CATEGORY = []
// 工具徽章 // 工具徽章
const BADGE_TOOL = ['text','hexString'] const BADGE_TOOL = []
// 默认常用工具 // 默认常用工具
const DEFAULT_COMMON_TOOL = [ const DEFAULT_COMMON_TOOL = [
'hash', 'encrypt', 'json', 'base64', 'url', 'timestamp', 'hash', 'encrypt', 'json', 'base64', 'url', 'timestamp',
...@@ -129,4 +129,4 @@ module.exports = { ...@@ -129,4 +129,4 @@ module.exports = {
badgeCategory: BADGE_CATEGORY, badgeCategory: BADGE_CATEGORY,
badgeTool: BADGE_TOOL, badgeTool: BADGE_TOOL,
defaultCommonTool: DEFAULT_COMMON_TOOL defaultCommonTool: DEFAULT_COMMON_TOOL
} }
\ No newline at end of file
import _ from 'lodash'
const MAX_NUM = 14 //格式化后的最长限制 const MAX_NUM = 14 //格式化后的最长限制
const DECIMAL_NUM = 7 //四舍五入时小数点后位数 const DECIMAL_NUM = 7 //四舍五入时小数点后位数
const EXPONENTIAL_NUM = 4 //科学计数法小数点后位数 const EXPONENTIAL_NUM = 4 //科学计数法小数点后位数
let CONFIG = [ const CONFIG = {
{ "length": {
key: "length", "name": "长度",
main: "m", "main": "",
unit: [ "unit": [
{ {
key: "km", "name": "千米",
unit: "km", "zh": "千米",
calc: (x) => (x * 1) / 1000, "en": "km",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "m", "name": "",
unit: "m", "zh": "",
calc: (x) => (x * 1), "en": "m",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "dm", "name": "分米",
unit: "dm", "zh": "分米",
calc: (x) => (x * 1) / 0.1, "en": "dm",
init: (x) => (x * 0.1) "calc": (x) => (x * 1) / 0.1,
"init": (x) => (x * 0.1)
}, },
{ {
key: "cm", "name": "厘米",
unit: "cm", "zh": "厘米",
calc: (x) => (x * 1) / 0.01, "en": "cm",
init: (x) => (x * 0.01) "calc": (x) => (x * 1) / 0.01,
"init": (x) => (x * 0.01)
}, },
{ {
key: "mm", "name": "毫米",
unit: "mm", "zh": "毫米",
calc: (x) => (x * 1) / 0.001, "en": "mm",
init: (x) => (x * 0.001) "calc": (x) => (x * 1) / 0.001,
"init": (x) => (x * 0.001)
}, },
{ {
key: "um", "name": "微米",
unit: "um", "zh": "微米",
calc: (x) => (x * 1) / 0.000001, "en": "um",
init: (x) => (x * 0.000001) "calc": (x) => (x * 1) / 0.000001,
"init": (x) => (x * 0.000001)
}, },
{ {
key: "nm", "name": "纳米",
unit: "nm", "zh": "纳米",
calc: (x) => (x * 1) / 0.000000001, "en": "nm",
init: (x) => (x * 0.000000001) "calc": (x) => (x * 1) / 0.000000001,
"init": (x) => (x * 0.000000001)
}, },
{ {
key: "pm", "name": "皮米",
unit: "pm", "zh": "皮米",
calc: (x) => (x * 1) / 0.000000000001, "en": "pm",
init: (x) => (x * 0.000000000001) "calc": (x) => (x * 1) / 0.000000000001,
"init": (x) => (x * 0.000000000001)
}, },
{ {
key: "ly", "name": "光年",
unit: "ly", "zh": "光年",
calc: (x) => (x * 1) / 9460730472580800, "en": "ly",
init: (x) => (x * 9460730472580800) "calc": (x) => (x * 1) / 9460730472580800,
"init": (x) => (x * 9460730472580800)
}, },
{ {
key: "au", "name": "天文单位",
unit: "AU", "zh": "天文单位",
calc: (x) => (x * 1) / 149597870700, "en": "AU",
init: (x) => (x * 149600000000) "calc": (x) => (x * 1) / 149597870700,
"init": (x) => (x * 149600000000)
}, },
{ {
key: "in", "name": "英寸",
unit: "in", "zh": "英寸",
calc: (x) => (x * 1) / (0.3048 / 12), "en": "in",
init: (x) => (x * (0.3048 / 12)) "calc": (x) => (x * 1) / (0.3048 / 12),
"init": (x) => (x * (0.3048 / 12))
}, },
{ {
key: "ft", "name": "英尺",
unit: "ft", "zh": "英尺",
calc: (x) => (x * 1) / 0.3048, "en": "ft",
init: (x) => (x * 0.3048) "calc": (x) => (x * 1) / 0.3048,
"init": (x) => (x * 0.3048)
}, },
{ {
key: "yd", "name": "",
unit: "yd", "zh": "",
calc: (x) => (x * 1) / (0.3048 * 3), "en": "yd",
init: (x) => (x * (0.3048 * 3)) "calc": (x) => (x * 1) / (0.3048 * 3),
"init": (x) => (x * (0.3048 * 3))
}, },
{ {
key: "mi", "name": "英里",
unit: "mi", "zh": "英里",
calc: (x) => (x * 1) / (0.3048 * 3 * 1760), "en": "mi",
init: (x) => (x * (0.3048 * 3 * 1760)) "calc": (x) => (x * 1) / (0.3048 * 3 * 1760),
"init": (x) => (x * (0.3048 * 3 * 1760))
}, },
{ {
key: "nmi", "name": "海里",
unit: "nmi", "zh": "海里",
calc: (x) => (x * 1) / 1852, "en": "nmi",
init: (x) => (x * 1852) "calc": (x) => (x * 1) / 1852,
"init": (x) => (x * 1852)
}, },
{ {
key: "fm", "name": "英寻",
unit: "fm", "zh": "英寻",
calc: (x) => (x * 1) / 1.8288, "en": "fm",
init: (x) => (x * 1.8288) "calc": (x) => (x * 1) / 1.8288,
"init": (x) => (x * 1.8288)
}, },
{ {
key: "fur", "name": "弗隆",
unit: "fur", "zh": "弗隆",
calc: (x) => (x * 1) / 201.168, "en": "fur",
init: (x) => (x * 201.168) "calc": (x) => (x * 1) / 201.168,
"init": (x) => (x * 201.168)
}, },
{ {
key: "cn_li", "name": "",
unit: "li", "zh": "",
calc: (x) => (x * 1) / 500, "en": "",
init: (x) => (x * 500) "calc": (x) => (x * 1) / 500,
"init": (x) => (x * 500)
}, },
{ {
key: "cn_zhang", "name": "",
unit: "zhang", "zh": "",
calc: (x) => (x * 1) / (10 / 3), "en": "",
init: (x) => (x * (10 / 3)) "calc": (x) => (x * 1) / (10 / 3),
"init": (x) => (x * (10 / 3))
}, },
{ {
key: "cn_chi", "name": "",
unit: "chi", "zh": "",
calc: (x) => (x * 1) / (1 / 3), "en": "",
init: (x) => (x * (1 / 3)) "calc": (x) => (x * 1) / (1 / 3),
"init": (x) => (x * (1 / 3))
}, },
{ {
key: "cn_cun", "name": "",
unit: "cun", "zh": "",
calc: (x) => (x * 1) / (0.1 / 3), "en": "",
init: (x) => (x * (0.1 / 3)) "calc": (x) => (x * 1) / (0.1 / 3),
"init": (x) => (x * (0.1 / 3))
}, },
{ {
key: "cn_fen", "name": "",
unit: "fen", "zh": "",
calc: (x) => (x * 1) / (0.01 / 3), "en": "",
init: (x) => (x * (0.01 / 3)) "calc": (x) => (x * 1) / (0.01 / 3),
"init": (x) => (x * (0.01 / 3))
}, },
{ {
key: "cn_li2", "name": "",
unit: "li", "zh": "",
calc: (x) => (x * 1) / (0.001 / 3), "en": "",
init: (x) => (x * (0.001 / 3)) "calc": (x) => (x * 1) / (0.001 / 3),
"init": (x) => (x * (0.001 / 3))
}, },
{ {
key: "cn_hao", "name": "",
unit: "hao", "zh": "",
calc: (x) => (x * 1) / (0.0001 / 3), "en": "",
init: (x) => (x * (0.0001 / 3)) "calc": (x) => (x * 1) / (0.0001 / 3),
"init": (x) => (x * (0.0001 / 3))
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "metric_system", "name": "公制",
list: ["km", "m", "dm", "cm", "mm", "um", "nm", "pm", "ly", "au"] "list": [
}, "千米",
{ "",
key: "imperial_units", "分米",
list: ["in", "ft", "yd", "mi", "nmi", "fm", "fur"] "厘米",
}, "毫米",
{ "微米",
key: "chinese_units", "纳米",
list: ["cn_li", "cn_zhang", "cn_chi", "cn_cun", "cn_fen", "cn_li2", "cn_hao"] "皮米",
"光年",
"天文单位"
]
},
{
"name": "英制",
"list": [
"英寸",
"英尺",
"",
"英里",
"海里",
"英寻",
"弗隆"
]
},
{
"name": "市制",
"list": [
"",
"",
"",
"",
"",
"",
""
]
} }
] ]
}, },
{ "area": {
key: "area", "name": "面积",
main: "m_2", "main": "平方米",
unit: [ "unit": [
{ {
key: "km_2", "name": "平方千米",
unit: "km²", "zh": "平方千米",
calc: (x) => (x * 1) / 1000000, "en": "km²",
init: (x) => (x * 1000000) "calc": (x) => (x * 1) / 1000000,
"init": (x) => (x * 1000000)
}, },
{ {
key: "ha", "name": "公顷",
unit: "ha", "zh": "公顷",
calc: (x) => (x * 1) / 10000, "en": "ha",
init: (x) => (x * 10000) "calc": (x) => (x * 1) / 10000,
"init": (x) => (x * 10000)
}, },
{ {
key: "are", "name": "公亩",
unit: "are", "zh": "公亩",
calc: (x) => (x * 1) / 100, "en": "are",
init: (x) => (x * 100) "calc": (x) => (x * 1) / 100,
"init": (x) => (x * 100)
}, },
{ {
key: "m_2", "name": "平方米",
unit: "", "zh": "平方米",
calc: (x) => (x * 1), "en": "",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "dm_2", "name": "平方分米",
unit: "dm²", "zh": "平方分米",
calc: (x) => (x * 1) / 0.01, "en": "dm²",
init: (x) => (x * 0.01) "calc": (x) => (x * 1) / 0.01,
"init": (x) => (x * 0.01)
}, },
{ {
key: "cm_2", "name": "平方厘米",
unit: "cm²", "zh": "平方厘米",
calc: (x) => (x * 1) / 0.0001, "en": "cm²",
init: (x) => (x * 0.0001) "calc": (x) => (x * 1) / 0.0001,
"init": (x) => (x * 0.0001)
}, },
{ {
key: "mm_2", "name": "平方毫米",
unit: "mm²", "zh": "平方毫米",
calc: (x) => (x * 1) / 0.000001, "en": "mm²",
init: (x) => (x * 0.000001) "calc": (x) => (x * 1) / 0.000001,
"init": (x) => (x * 0.000001)
}, },
{ {
key: "acre", "name": "英亩",
unit: "acre", "zh": "英亩",
calc: (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160), "en": "acre",
init: (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160)) "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160),
"init": (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160))
}, },
{ {
key: "mi_2", "name": "平方英里",
unit: "mi²", "zh": "平方英里",
calc: (x) => (x * 1) / Math.pow((0.3048 * 3 * 1760), 2), "en": "sq.mi",
init: (x) => (x * Math.pow((0.3048 * 3 * 1760), 2)) "calc": (x) => (x * 1) / Math.pow((0.3048 * 3 * 1760), 2),
"init": (x) => (x * Math.pow((0.3048 * 3 * 1760), 2))
}, },
{ {
key: "yd_2", "name": "平方码",
unit: "yd²", "zh": "平方码",
calc: (x) => (x * 1) / (Math.pow(0.3048, 2) * 9), "en": "sq.yd",
init: (x) => (x * (Math.pow(0.3048, 2) * 9)) "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * 9),
"init": (x) => (x * (Math.pow(0.3048, 2) * 9))
}, },
{ {
key: "ft_2", "name": "平方英尺",
unit: "ft²", "zh": "平方英尺",
calc: (x) => (x * 1) / Math.pow(0.3048, 2), "en": "sq.ft",
init: (x) => (x * (Math.pow(0.3048, 2))) "calc": (x) => (x * 1) / Math.pow(0.3048, 2),
"init": (x) => (x * (Math.pow(0.3048, 2)))
}, },
{ {
key: "in_2", "name": "平方英寸",
unit: "in²", "zh": "平方英寸",
calc: (x) => (x * 1) / (Math.pow(0.3048, 2) / 144), "en": "sq.in",
init: (x) => (x * (Math.pow(0.3048, 2) / 144)) "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) / 144),
"init": (x) => (x * (Math.pow(0.3048, 2) / 144))
}, },
{ {
key: "rd_2", "name": "平方竿",
unit: "rd²", "zh": "平方竿",
calc: (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2)), "en": "sq.rd",
init: (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2))) "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2)),
"init": (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2)))
}, },
{ {
key: "cn_qing", "name": "",
unit: "qing", "zh": "",
calc: (x) => (x * 1) / (100 / 0.0015), "en": "",
init: (x) => (x * (100 / 0.0015)) "calc": (x) => (x * 1) / (100 / 0.0015),
"init": (x) => (x * (100 / 0.0015))
}, },
{ {
key: "cn_mu", "name": "",
unit: "mu", "zh": "",
calc: (x) => (x * 1) / (1 / 0.0015), "en": "",
init: (x) => (x * (1 / 0.0015)) "calc": (x) => (x * 1) / (1 / 0.0015),
"init": (x) => (x * (1 / 0.0015))
}, },
{ {
key: "cn_fen", "name": "",
unit: "fen", "zh": "",
calc: (x) => (x * 1) / (1 / 0.015), "en": "",
init: (x) => (x * (1 / 0.015)) "calc": (x) => (x * 1) / (1 / 0.015),
"init": (x) => (x * (1 / 0.015))
}, },
{ {
key: "cn_chi_2", "name": "平方尺",
unit: "chi²", "zh": "平方尺",
calc: (x) => (x * 1) / (1 / 9), "en": "",
init: (x) => (x * (1 / 9)) "calc": (x) => (x * 1) / (1 / 9),
"init": (x) => (x * (1 / 9))
}, },
{ {
key: "cn_cun_2", "name": "平方寸",
unit: "cun²", "zh": "平方寸",
calc: (x) => (x * 1) / (0.01 / 9), "en": "",
init: (x) => (x * (0.01 / 9)) "calc": (x) => (x * 1) / (0.01 / 9),
"init": (x) => (x * (0.01 / 9))
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "metric_system", "name": "公制",
list: ["km_2", "ha", "are", "m_2", "dm_2", "cm_2", "mm_2"] "list": [
}, "平方千米",
{ "公顷",
key: "imperial_units", "公亩",
list: ["acre", "mi_2", "yd_2", "ft_2", "in_2", "rd_2"] "平方米",
}, "平方分米",
{ "平方厘米",
key: "chinese_units", "平方毫米"
list: ["cn_qing", "cn_mu", "cn_fen", "cn_chi_2", "cn_cun_2"] ]
},
{
"name": "英制",
"list": [
"英亩",
"平方英里",
"平方码",
"平方英尺",
"平方英寸",
"平方竿"
]
},
{
"name": "市制",
"list": [
"",
"",
"",
"平方尺",
"平方寸"
]
} }
] ]
}, },
{ "volume": {
key: "volume", "name": "体积",
main: "m_3", "main": "立方米",
unit: [ "unit": [
{ {
key: "m_3", "name": "立方米",
unit: "", "zh": "立方米",
calc: (x) => (x * 1), "en": "",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "dm_3", "name": "立方分米",
unit: "dm³", "zh": "立方分米",
calc: (x) => (x * 1) / 0.001, "en": "dm³",
init: (x) => (x * 0.001) "calc": (x) => (x * 1) / 0.001,
"init": (x) => (x * 0.001)
}, },
{ {
key: "cm_3", "name": "立方厘米",
unit: "cm³", "zh": "立方厘米",
calc: (x) => (x * 1) / 0.000001, "en": "cm³",
init: (x) => (x * 0.000001) "calc": (x) => (x * 1) / 0.000001,
"init": (x) => (x * 0.000001)
}, },
{ {
key: "mm_3", "name": "立方毫米",
unit: "mm³", "zh": "立方毫米",
calc: (x) => (x * 1) / 0.000000001, "en": "mm³",
init: (x) => (x * 0.000000001) "calc": (x) => (x * 1) / 0.000000001,
"init": (x) => (x * 0.000000001)
}, },
{ {
key: "l", "name": "",
unit: "l", "zh": "",
calc: (x) => (x * 1) / 0.001, "en": "l",
init: (x) => (x * 0.001) "calc": (x) => (x * 1) / 0.001,
"init": (x) => (x * 0.001)
}, },
{ {
key: "dl", "name": "分升",
unit: "dl", "zh": "分升",
calc: (x) => (x * 1) / 0.0001, "en": "dl",
init: (x) => (x * 0.0001) "calc": (x) => (x * 1) / 0.0001,
"init": (x) => (x * 0.0001)
}, },
{ {
key: "ml", "name": "毫升",
unit: "ml", "zh": "毫升",
calc: (x) => (x * 1) / 0.000001, "en": "ml",
init: (x) => (x * 0.000001) "calc": (x) => (x * 1) / 0.000001,
"init": (x) => (x * 0.000001)
}, },
{ {
key: "cl", "name": "厘升",
unit: "cl", "zh": "厘升",
calc: (x) => (x * 1) / 0.00001, "en": "cl",
init: (x) => (x * 0.00001) "calc": (x) => (x * 1) / 0.00001,
"init": (x) => (x * 0.00001)
}, },
{ {
key: "uL", "name": "公石",
unit: "μL", "zh": "公石",
calc: (x) => (x * 1) / 0.000000001, "en": "hl",
init: (x) => (x * 0.000000001) "calc": (x) => (x * 1) / 0.1,
"init": (x) => (x * 0.1)
}, },
{ {
key: "hl", "name": "立方英尺",
unit: "hl", "zh": "立方英尺",
calc: (x) => (x * 1) / 0.1, "en": "cu ft",
init: (x) => (x * 0.1) "calc": (x) => (x * 1) / 0.0283168,
"init": (x) => (x * 0.0283168)
}, },
{ {
key: "ft_3", "name": "立方英寸",
unit: "ft_3", "zh": "立方英寸",
calc: (x) => (x * 1) / 0.0283168, "en": "cu in",
init: (x) => (x * 0.0283168) "calc": (x) => (x * 1) / (0.0283168 / 1728),
"init": (x) => (x * (0.0283168 / 1728))
}, },
{ {
key: "in_3", "name": "立方码",
unit: "in_3", "zh": "立方码",
calc: (x) => (x * 1) / (0.0283168 / 1728), "en": "cu yd",
init: (x) => (x * (0.0283168 / 1728)) "calc": (x) => (x * 1) / (0.0283168 * 27),
"init": (x) => (x * (0.0283168 * 27))
}, },
{ {
key: "yd_3", "name": "亩英尺",
unit: "yd_3", "zh": "亩英尺",
calc: (x) => (x * 1) / (0.0283168 * 27), "en": "",
init: (x) => (x * (0.0283168 * 27)) "calc": (x) => (x * 1) / (43560 * 1728 * 0.016387064 / 1000),
"init": (x) => (x * (43560 * 1728 * 0.016387064 / 1000))
}, },
{ {
key: "acre_ft", "name": "英制加仑",
unit: "acre ft", "zh": "英制加仑",
calc: (x) => (x * 1) / (43560 * 1728 * 0.016387064 / 1000), "en": "uk gal",
init: (x) => (x * (43560 * 1728 * 0.016387064 / 1000)) "calc": (x) => (x * 1) / 0.00454609188,
"init": (x) => (x * 0.00454609188)
}, },
{ {
key: "uk_gal", "name": "美制加仑",
unit: "uk gal", "zh": "美制加仑",
calc: (x) => (x * 1) / 0.00454609188, "en": "us gal",
init: (x) => (x * 0.00454609188) "calc": (x) => (x * 1) / (231 * 0.016387064 / 1000),
"init": (x) => (x * (231 * 0.016387064 / 1000))
}, },
{ {
key: "us_gal", "name": "微升",
unit: "us gal", "zh": "微升",
calc: (x) => (x * 1) / (231 * 0.016387064 / 1000), "en": "ul",
init: (x) => (x * (231 * 0.016387064 / 1000)) "calc": (x) => (x * 1) / 0.000000001,
"init": (x) => (x * 0.000000001)
}, },
{ {
key: "uk_oz", "name": "英制液体盎司",
unit: "uk oz", "zh": "英制液体盎司",
calc: (x) => (x * 1) / (0.000001 * 28.41), "en": "oz",
init: (x) => (x * 0.000001 * 28.41) "calc": (x) => (x * 1) / (0.000001 * 28.41),
"init": (x) => (x * 0.000001 * 28.41)
}, },
{ {
key: "us_oz", "name": "美制液体盎司",
unit: "us oz", "zh": "美制液体盎司",
calc: (x) => (x * 1) / (0.000001 * 29.57), "en": "oz",
init: (x) => (x * 0.000001 * 29.57) "calc": (x) => (x * 1) / (0.000001 * 29.57),
"init": (x) => (x * 0.000001 * 29.57)
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "metric_system", "name": "公制",
list: ["m_3", "dm_3", "cm_3", "mm_3", "l", "dl", "ml", "cl", "uL", "hl"] "list": [
}, "立方米",
{ "立方分米",
key: "imperial_units", "立方厘米",
list: ["ft_3", "in_3", "yd_3", "acre_ft", "uk_gal", "us_gal", "uk_oz", "us_oz"] "立方毫米",
"",
"分升",
"毫升",
"厘升",
"公石",
"微升"
]
},
{
"name": "英制",
"list": [
"立方英尺",
"立方英寸",
"立方码",
"亩英尺",
"英制加仑",
"美制加仑",
"英制液体盎司",
"美制液体盎司"
]
} }
] ]
}, },
{ "weight": {
key: "weight", "name": "质量",
main: "kg", "main": "千克",
unit: [ "unit": [
{
key: "kg",
unit: "kg",
calc: (x) => (x * 1),
init: (x) => (x * 1)
},
{ {
key: "g", "name": "千克",
unit: "g", "zh": "千克",
calc: (x) => (x * 1) / 0.001, "en": "kg",
init: (x) => (x * 0.001) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "mg", "name": "",
unit: "mg", "zh": "",
calc: (x) => (x * 1) / 0.000001, "en": "g",
init: (x) => (x * 0.000001) "calc": (x) => (x * 1) / 0.001,
"init": (x) => (x * 0.001)
}, },
{ {
key: "ug", "name": "毫克",
unit: "μg", "zh": "毫克",
calc: (x) => (x * 1) / 0.000000001, "en": "mg",
init: (x) => (x * 0.000000001) "calc": (x) => (x * 1) / 0.000001,
"init": (x) => (x * 0.000001)
}, },
{ {
key: "t", "name": "微克",
unit: "t", "zh": "微克",
calc: (x) => (x * 1) / 1000, "en": "μg",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 0.000000001,
"init": (x) => (x * 0.000000001)
}, },
{ {
key: "q", "name": "",
unit: "q", "zh": "",
calc: (x) => (x * 1) / 100, "en": "t",
init: (x) => (x * 100) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "ct", "name": "公担",
unit: "ct", "zh": "公担",
calc: (x) => (x * 1) / 0.0002, "en": "q",
init: (x) => (x * 0.0002) "calc": (x) => (x * 1) / 100,
"init": (x) => (x * 100)
}, },
{ {
key: "lb", "name": "",
unit: "lb", "zh": "",
calc: (x) => (x * 1) / 0.45359237, "en": "lb",
init: (x) => (x * 0.45359237) "calc": (x) => (x * 1) / 0.45359237,
"init": (x) => (x * 0.45359237)
}, },
{ {
key: "oz", "name": "盎司",
unit: "oz", "zh": "盎司",
calc: (x) => (x * 1) / (0.45359237 / 16), "en": "oz",
init: (x) => (x * (0.45359237 / 16)) "calc": (x) => (x * 1) / (0.45359237 / 16),
"init": (x) => (x * (0.45359237 / 16))
}, },
{ {
key: "gr", "name": "克拉",
unit: "gr", "zh": "克拉",
calc: (x) => (x * 1) / (0.45359237 / 7000), "en": "ct",
init: (x) => (x * (0.45359237 / 7000)) "calc": (x) => (x * 1) / 0.0002,
"init": (x) => (x * 0.0002)
}, },
{ {
key: "lt", "name": "格令",
unit: "lt", "zh": "格令",
calc: (x) => (x * 1) / (0.45359237 * 2240), "en": "gr",
init: (x) => (x * (0.45359237 * 2240)) "calc": (x) => (x * 1) / (0.45359237 / 7000),
"init": (x) => (x * (0.45359237 / 7000))
}, },
{ {
key: "st1", "name": "长吨",
unit: "st", "zh": "长吨",
calc: (x) => (x * 1) / (0.45359237 * 2000), "en": "lt",
init: (x) => (x * (0.45359237 * 2000)) "calc": (x) => (x * 1) / (0.45359237 * 2240),
"init": (x) => (x * (0.45359237 * 2240))
}, },
{ {
key: "uk_cwt", "name": "短吨",
unit: "uk cwt", "zh": "短吨",
calc: (x) => (x * 1) / (0.45359237 * 112), "en": "st",
init: (x) => (x * (0.45359237 * 112)) "calc": (x) => (x * 1) / (0.45359237 * 2000),
"init": (x) => (x * (0.45359237 * 2000))
}, },
{ {
key: "us_cwt", "name": "英担",
unit: "us cwt", "zh": "英担",
calc: (x) => (x * 1) / (0.45359237 * 100), "en": "",
init: (x) => (x * (0.45359237 * 100)) "calc": (x) => (x * 1) / (0.45359237 * 112),
"init": (x) => (x * (0.45359237 * 112))
}, },
{ {
key: "st2", "name": "美担",
unit: "st", "zh": "美担",
calc: (x) => (x * 1) / (0.45359237 * 14), "en": "",
init: (x) => (x * (0.45359237 * 14)) "calc": (x) => (x * 1) / (0.45359237 * 100),
"init": (x) => (x * (0.45359237 * 100))
}, },
{ {
key: "dr", "name": "英石",
unit: "dr", "zh": "英石",
calc: (x) => (x * 1) / (0.45359237 / 256), "en": "st",
init: (x) => (x * (0.45359237 / 256)) "calc": (x) => (x * 1) / (0.45359237 * 14),
"init": (x) => (x * (0.45359237 * 14))
}, },
{ {
key: "cn_dan", "name": "打兰",
unit: "dan", "zh": "打兰",
calc: (x) => (x * 1) / 50, "en": "dr",
init: (x) => (x * 50) "calc": (x) => (x * 1) / (0.45359237 / 256),
"init": (x) => (x * (0.45359237 / 256))
}, },
{ {
key: "cn_jin", "name": "",
unit: "jin", "zh": "",
calc: (x) => (x * 1) / 0.5, "en": "",
init: (x) => (x * 0.5) "calc": (x) => (x * 1) / 50,
"init": (x) => (x * 50)
}, },
{ {
key: "cn_liang", "name": "",
unit: "liang", "zh": "",
calc: (x) => (x * 1) / 0.05, "en": "",
init: (x) => (x * 0.05) "calc": (x) => (x * 1) / 0.5,
"init": (x) => (x * 0.5)
}, },
{ {
key: "cn_qian", "name": "",
unit: "qian", "zh": "",
calc: (x) => (x * 1) / 0.005, "en": "",
init: (x) => (x * 0.005) "calc": (x) => (x * 1) / 0.05,
} "init": (x) => (x * 0.05)
],
special: [],
group: [
{
key: "metric_system",
list: ["kg", "g", "mg", "ug", "t", "q", "ct"]
}, },
{ {
key: "imperial_units", "name": "",
list: ["lb", "oz", "gr", "lt", "st1", "uk_cwt", "us_cwt", "st2", "dr"] "zh": "",
"en": "",
"calc": (x) => (x * 1) / 0.005,
"init": (x) => (x * 0.005)
}, },
{ {
key: "chinese_units", "name": "",
list: ["cn_dan", "cn_jin", "cn_liang", "cn_qian"] "zh": "",
"en": "point",
"calc": (x) => (x * 1) / 0.000002,
"init": (x) => (x * 0.000002)
}
],
"special": [],
"group": [
{
"name": "公制",
"list": [
"千克",
"",
"毫克",
"微克",
"",
"公担",
"克拉",
""
]
},
{
"name": "英制",
"list": [
"",
"盎司",
"克拉",
"格令",
"长吨",
"短吨",
"英担",
"美担",
"英石",
"打兰"
]
},
{
"name": "市制",
"list": [
"",
"",
"",
""
]
} }
] ]
}, },
{ "temperature": {
key: "temperature", "name": "温度",
main: "k", "main": "开氏度",
unit: [ "unit": [
{ {
key: "c", "name": "摄氏度",
unit: "°C", "zh": "摄氏度",
calc: (x) => (x - 273.15), "en": "",
init: (x) => (x * 1) + 273.15 "calc": (x) => (x - 273.15),
"init": (x) => (x * 1) + 273.15
}, },
{ {
key: "f", "name": "华氏度",
unit: "°F", "zh": "华氏度",
calc: (x) => 32 + ((x - 273.15) * 9 / 5), "en": "",
init: (x) => (5 * (x - 32) / 9) + 273.15 "calc": (x) => 32 + ((x - 273.15) * 9 / 5),
"init": (x) => (5 * (x - 32) / 9) + 273.15
}, },
{ {
key: "k", "name": "开氏度",
unit: "K", "zh": "开氏度",
calc: (x) => (x - 273.15) + 273.15, "en": "K",
init: (x) => (x - 273.15) + 273.15 "calc": (x) => (x - 273.15) + 273.15,
"init": (x) => (x - 273.15) + 273.15
}, },
{ {
key: "r", "name": "兰氏度",
unit: "°R", "zh": "兰氏度",
calc: (x) => ((x - 273.15) + 273.15) * 1.8, "en": "°R",
init: (x) => (x / 1.8 - 273.15) + 273.15 "calc": (x) => ((x - 273.15) + 273.15) * 1.8,
"init": (x) => (x / 1.8 - 273.15) + 273.15
}, },
{ {
key: "re", "name": "列氏度",
unit: "°Re", "zh": "列氏度",
calc: (x) => (x - 273.15) / 1.25, "en": "°Re",
init: (x) => (x * 1.25) + 273.15 "calc": (x) => (x - 273.15) / 1.25,
"init": (x) => (x * 1.25) + 273.15
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["c", "f", "k", "r", "re"] "list": [
"摄氏度",
"华氏度",
"开氏度",
"兰氏度",
"列氏度"
]
} }
] ]
}, },
{ "pressure": {
key: "pressure", "name": "压力",
main: "pa", "main": "帕斯卡",
unit: [ "unit": [
{ {
key: "pa", "name": "帕斯卡",
unit: "Pa", "zh": "帕斯卡",
calc: (x) => (x * 1), "en": "Pa",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "kpa", "name": "千帕",
unit: "kpa", "zh": "千帕",
calc: (x) => (x * 1) / 1000, "en": "kpa",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "hpa", "name": "百帕",
unit: "hpa", "zh": "百帕",
calc: (x) => (x * 1) / 100, "en": "hpa",
init: (x) => (x * 100) "calc": (x) => (x * 1) / 100,
"init": (x) => (x * 100)
}, },
{ {
key: "atm", "name": "标准大气压",
unit: "atm", "zh": "标准大气压",
calc: (x) => (x * 1) / 101325, "en": "atm",
init: (x) => (x * 101325) "calc": (x) => (x * 1) / 101325,
"init": (x) => (x * 101325)
}, },
{ {
key: "mmhg", "name": "毫米汞柱",
unit: "mmHg", "zh": "毫米汞柱",
calc: (x) => (x * 1) / (101325 / 760), "en": "mmHg",
init: (x) => (x * (101325 / 760)) "calc": (x) => (x * 1) / (101325 / 760),
"init": (x) => (x * (101325 / 760))
}, },
{ {
key: "in_hg", "name": "英寸汞柱",
unit: "in Hg", "zh": "英寸汞柱",
calc: (x) => (x * 1) / (101325 / 760 * 25.4), "en": "in Hg",
init: (x) => (x * (101325 / 760 * 25.4)) "calc": (x) => (x * 1) / (101325 / 760 * 25.4),
"init": (x) => (x * (101325 / 760 * 25.4))
}, },
{ {
key: "bar", "name": "",
unit: "bar", "zh": "",
calc: (x) => (x * 1) / 100000, "en": "bar",
init: (x) => (x * 100000) "calc": (x) => (x * 1) / 100000,
"init": (x) => (x * 100000)
}, },
{ {
key: "mbar", "name": "毫巴",
unit: "mbar", "zh": "毫巴",
calc: (x) => (x * 1) / 100, "en": "mbar",
init: (x) => (x * 100) "calc": (x) => (x * 1) / 100,
"init": (x) => (x * 100)
}, },
{ {
key: "psf", "name": "磅力/平方英尺",
unit: "psf", "zh": "磅力/平方英尺",
calc: (x) => (x * 1) / (6894.757 / 144), "en": "psf",
init: (x) => (x * (6894.757 / 144)) "calc": (x) => (x * 1) / (6894.757 / 144),
"init": (x) => (x * (6894.757 / 144))
}, },
{ {
key: "psi", "name": "磅力/平方英寸",
unit: "psi", "zh": "磅力/平方英寸",
calc: (x) => (x * 1) / 6894.757, "en": "psi",
init: (x) => (x * 6894.757) "calc": (x) => (x * 1) / 6894.757,
"init": (x) => (x * 6894.757)
}, },
{ {
key: "mmwg", "name": "毫米水柱",
unit: "mmWG", "zh": "毫米水柱",
calc: (x) => (x * 1) / (1 / 0.101972), "en": "",
init: (x) => (x * (1 / 0.101972)) "calc": (x) => (x * 1) / (1 / 0.101972),
"init": (x) => (x * (1 / 0.101972))
}, },
{ {
key: "kgf_cm_2", "name": "公斤力/平方厘米",
unit: "kgf/cm²", "zh": "公斤力/平方厘米",
calc: (x) => (x * 1) / 98066.5, "en": "kgf/cm²",
init: (x) => (x * 98066.5) "calc": (x) => (x * 1) / 98066.5,
"init": (x) => (x * 98066.5)
}, },
{ {
key: "kgf_m_2", "name": "公斤力/平方米",
unit: "kgf/m²", "zh": "公斤力/平方米",
calc: (x) => (x * 1) / 9.80665, "en": "kgf/㎡",
init: (x) => (x * 9.80665) "calc": (x) => (x * 1) / 9.80665,
"init": (x) => (x * 9.80665)
}, },
{ {
key: "mpa", "name": "兆帕",
unit: "MPa", "zh": "兆帕",
calc: (x) => (x * 1) / 1000000, "en": "MPa",
init: (x) => (x * 1000000) "calc": (x) => (x * 1) / 1000000,
"init": (x) => (x * 1000000)
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["pa", "kpa", "hpa", "atm", "mmhg", "in_hg", "bar", "mbar", "psf", "psi", "mmwg", "kgf_cm_2", "kgf_m_2", "mpa"] "list": [
"帕斯卡",
"兆帕",
"千帕",
"百帕",
"标准大气压",
"毫米汞柱",
"英寸汞柱",
"",
"毫巴",
"磅力/平方英尺",
"磅力/平方英寸",
"毫米水柱",
"公斤力/平方厘米",
"公斤力/平方米"
]
} }
] ]
}, },
{ "power": {
key: "power", "name": "功率",
main: "w", "main": "",
unit: [ "unit": [
{ {
key: "w", "name": "",
unit: "W", "zh": "",
calc: (x) => (x * 1), "en": "W",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "kw", "name": "千瓦",
unit: "kW", "zh": "千瓦",
calc: (x) => (x * 1) / 1000, "en": "kW",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "hp", "name": "英制马力",
unit: "hp", "zh": "英制马力",
calc: (x) => (x * 1) / 745.699872, "en": "hp",
init: (x) => (x * 745.699872) "calc": (x) => (x * 1) / 745.699872,
"init": (x) => (x * 745.699872)
}, },
{ {
key: "ps", "name": "米制马力",
unit: "ps", "zh": "米制马力",
calc: (x) => (x * 1) / (9.80665 * 75), "en": "ps",
init: (x) => (x * (9.80665 * 75)) "calc": (x) => (x * 1) / (9.80665 * 75),
"init": (x) => (x * (9.80665 * 75))
}, },
{ {
key: "kg_m_s", "name": "公斤·米/秒",
unit: "kg·m/s", "zh": "公斤·米/秒",
calc: (x) => (x * 1) / 9.80665, "en": "kg·m/s",
init: (x) => (x * 9.80665) "calc": (x) => (x * 1) / 9.80665,
"init": (x) => (x * 9.80665)
}, },
{ {
key: "kcal_s", "name": "千卡/秒",
unit: "kcal/s", "zh": "千卡/秒",
calc: (x) => (x * 1) / 4184.1004, "en": "kcal/s",
init: (x) => (x * 4184.1004) "calc": (x) => (x * 1) / 4184.1004,
"init": (x) => (x * 4184.1004)
}, },
{ {
key: "btu_s", "name": "英热单位/秒",
unit: "Btu/s", "zh": "英热单位/秒",
calc: (x) => (x * 1) / 1055.05585, "en": "Btu/s",
init: (x) => (x * 1055.05585) "calc": (x) => (x * 1) / 1055.05585,
"init": (x) => (x * 1055.05585)
}, },
{ {
key: "ft_lb_s", "name": "英尺·磅/秒",
unit: "ft·lb/s", "zh": "英尺·磅/秒",
calc: (x) => (x * 1) / (745.699872 / 550), "en": "ft·lb/s",
init: (x) => (x * (745.699872 / 550)) "calc": (x) => (x * 1) / (745.699872 / 550),
"init": (x) => (x * (745.699872 / 550))
}, },
{ {
key: "j_s", "name": "焦耳/秒",
unit: "J/s", "zh": "焦耳/秒",
calc: (x) => (x * 1), "en": "J/s",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "n_m_s", "name": "牛顿·米/秒",
unit: "N·m/s", "zh": "牛顿·米/秒",
calc: (x) => (x * 1), "en": "N·m/s",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["w", "kw", "hp", "ps", "kg_m_s", "kcal_s", "btu_s", "ft_lb_s", "j_s", "n_m_s"] "list": [
"",
"千瓦",
"英制马力",
"米制马力",
"公斤·米/秒",
"千卡/秒",
"英热单位/秒",
"英尺·磅/秒",
"焦耳/秒",
"牛顿·米/秒"
]
} }
] ]
}, },
{ "work": {
key: "work", "name": "功/能/热",
main: "j", "main": "焦耳",
unit: [ "unit": [
{ {
key: "j", "name": "焦耳",
unit: "J", "zh": "焦耳",
calc: (x) => (x * 1), "en": "J",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "kg_m", "name": "公斤·米",
unit: "kg·m", "zh": "公斤·米",
calc: (x) => (x * 1) / 9.80392157, "en": "kg·m",
init: (x) => (x * 9.80392157) "calc": (x) => (x * 1) / 9.80392157,
"init": (x) => (x * 9.80392157)
}, },
{ {
key: "ps_h", "name": "米制马力·时",
unit: "ps·h", "zh": "米制马力·时",
calc: (x) => (x * 1) / (9.80665 * 75 * 3600), "en": "ps·h",
init: (x) => (x * (9.80665 * 75 * 3600)) "calc": (x) => (x * 1) / (9.80665 * 75 * 3600),
"init": (x) => (x * (9.80665 * 75 * 3600))
}, },
{ {
key: "hp_h", "name": "英制马力·时",
unit: "hp·h", "zh": "英制马力·时",
calc: (x) => (x * 1) / (745.699872 * 3600), "en": "hp·h",
init: (x) => (x * (745.699872 * 3600)) "calc": (x) => (x * 1) / (745.699872 * 3600),
"init": (x) => (x * (745.699872 * 3600))
}, },
{ {
key: "kw_h", "name": "千瓦·时",
unit: "kW·h", "zh": "千瓦·时",
calc: (x) => (x * 1) / 3600000, "en": "kW·h",
init: (x) => (x * 3600000) "calc": (x) => (x * 1) / 3600000,
"init": (x) => (x * 3600000)
}, },
{ {
key: "kw_h_", "name": "",
unit: "kW·h", "zh": "",
calc: (x) => (x * 1) / 3600000, "en": "kW·h",
init: (x) => (x * 3600000) "calc": (x) => (x * 1) / 3600000,
"init": (x) => (x * 3600000)
}, },
{ {
key: "cal", "name": "",
unit: "cal", "zh": "",
calc: (x) => (x * 1) / 4.185851820846, "en": "cal",
init: (x) => (x * 4.185851820846) "calc": (x) => (x * 1) / 4.185851820846,
"init": (x) => (x * 4.185851820846)
}, },
{ {
key: "kcal", "name": "千卡",
unit: "kcal", "zh": "千卡",
calc: (x) => (x * 1) / 4185.851820846, "en": "kcal",
init: (x) => (x * 4185.851820846) "calc": (x) => (x * 1) / 4185.851820846,
"init": (x) => (x * 4185.851820846)
}, },
{ {
key: "btu", "name": "英热单位",
unit: "btu", "zh": "英热单位",
calc: (x) => (x * 1) / 1055.05585262, "en": "btu",
init: (x) => (x * 1055.05585262) "calc": (x) => (x * 1) / 1055.05585262,
"init": (x) => (x * 1055.05585262)
}, },
{ {
key: "ft_lb", "name": "英尺·磅",
unit: "ft·lb", "zh": "英尺·磅",
calc: (x) => (x * 1) / 1.3557483731, "en": "ft·lb",
init: (x) => (x * 1.3557483731) "calc": (x) => (x * 1) / 1.3557483731,
"init": (x) => (x * 1.3557483731)
}, },
{ {
key: "kj", "name": "千焦",
unit: "kJ", "zh": "千焦",
calc: (x) => (x * 1) / 1000, "en": "kJ",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "焦耳(J)",
list: ["j", "kg_m", "ps_h", "hp_h", "kw_h","kw_h_", "cal", "kcal", "btu", "ft_lb", "kj"] "list": [
"焦耳",
"公斤·米",
"米制马力·时",
"英制马力·时",
"千瓦·时",
"",
"",
"千卡",
"英热单位",
"英尺·磅",
"千焦"
]
} }
] ]
}, },
{ "density": {
key: "density", "name": "密度",
main: "kg_m_3", "main": "千克/立方米",
unit: [ "unit": [
{ {
key: "kg_cm_3", "name": "千克/立方厘米",
unit: "kg/cm³", "zh": "千克/立方厘米",
calc: (x) => (x * 1) / (Math.pow(10, 6)), "en": "kg/cm³",
init: (x) => (x * 1000000) "calc": (x) => (x * 1) / (Math.pow(10, 6)),
"init": (x) => (x * 1000000)
}, },
{ {
key: "kg_dm_3", "name": "千克/立方分米",
unit: "kg/dm³", "zh": "千克/立方分米",
calc: (x) => (x * 1) / 1000, "en": "kg/dm³",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "kg_m_3", "name": "千克/立方米",
unit: "kg/m³", "zh": "千克/立方米",
calc: (x) => (x * 1), "en": "kg/m³",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "g_cm_3", "name": "克/立方厘米",
unit: "g/cm³", "zh": "克/立方厘米",
calc: (x) => (x * 1) / 1000, "en": "g/cm³",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "g_dm_3", "name": "克/立方分米",
unit: "g/dm³", "zh": "克/立方分米",
calc: (x) => (x * 1), "en": "g/dm³",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "g_m_3", "name": "克/立方米",
unit: "g/m³", "zh": "克/立方米",
calc: (x) => (x * 1000), "en": "g/m³",
init: (x) => (x * 1) / 1000 "calc": (x) => (x * 1000),
"init": (x) => (x * 1) / 1000
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["kg_cm_3", "kg_dm_3", "kg_m_3", "g_cm_3", "g_dm_3", "g_m_3"] "list": [
"千克/立方厘米",
"千克/立方分米",
"千克/立方米",
"克/立方厘米",
"克/立方分米",
"克/立方米"
]
} }
] ]
}, },
{ "strength": {
key: "strength", "name": "",
main: "n", "main": "",
unit: [ "unit": [
{ {
key: "n", "name": "",
unit: "N", "zh": "",
calc: (x) => (x * 1), "en": "N",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "kn", "name": "千牛",
unit: "kN", "zh": "千牛",
calc: (x) => (x * 1) / 1000, "en": "kN",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "kgf", "name": "千克力",
unit: "kgf", "zh": "千克力",
calc: (x) => (x * 101.971621) / 1000, "en": "kgf",
init: (x) => (x * 9.806650) "calc": (x) => (x * 101.971621) / 1000,
"init": (x) => (x * 9.806650)
}, },
{ {
key: "gf", "name": "克力",
unit: "gf", "zh": "克力",
calc: (x) => (x * 101.971621), "en": "gf",
init: (x) => (x * 9.806650) / 1000 "calc": (x) => (x * 101.971621),
"init": (x) => (x * 9.806650) / 1000
}, },
{ {
key: "tf", "name": "公吨力",
unit: "tf", "zh": "公吨力",
calc: (x) => (x * 101.971621) / (Math.pow(10, 6)), "en": "tf",
init: (x) => (x * 9806.650000) "calc": (x) => (x * 101.971621) / (Math.pow(10, 6)),
"init": (x) => (x * 9806.650000)
}, },
{ {
key: "lbf", "name": "磅力",
unit: "lbf", "zh": "磅力",
calc: (x) => (x * 224.808943) / 1000, "en": "lbf",
init: (x) => (x * 4.448222) "calc": (x) => (x * 224.808943) / 1000,
"init": (x) => (x * 4.448222)
}, },
{ {
key: "kip", "name": "千磅力",
unit: "kip", "zh": "千磅力",
calc: (x) => (x * 224.808943) / (Math.pow(10, 6)), "en": "kip",
init: (x) => (x * 4448.221615) "calc": (x) => (x * 224.808943) / (Math.pow(10, 6)),
"init": (x) => (x * 4448.221615)
}, },
{ {
key: "dyn", "name": "达因",
unit: "dyn", "zh": "达因",
calc: (x) => (x * 100000), "en": "dyn",
init: (x) => (x * 1) / 100000 "calc": (x) => (x * 100000),
"init": (x) => (x * 1) / 100000
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["n", "kn", "kgf", "gf", "tf", "lbf", "kip", "dyn"] "list": [
"",
"千牛",
"千克力",
"克力",
"公吨力",
"磅力",
"千磅力",
"达因"
]
} }
] ]
}, },
{ "time": {
key: "time", "name": "时间",
main: "s", "main": "",
unit: [ "unit": [
{ {
key: "yr", "name": "",
unit: "yr", "zh": "",
calc: (x) => (x * 31.709792) / (Math.pow(10, 9)), "en": "yr",
init: (x) => (x * 31536000) "calc": (x) => (x * 31.709792) / (Math.pow(10, 9)),
"init": (x) => (x * 31536000)
}, },
{ {
key: "week", "name": "",
unit: "week", "zh": "",
calc: (x) => (x * 1.653439) / (Math.pow(10, 6)), "en": "week",
init: (x) => (x * 604800) "calc": (x) => (x * 1.653439) / (Math.pow(10, 6)),
"init": (x) => (x * 604800)
}, },
{ {
key: "d", "name": "",
unit: "d", "zh": "",
calc: (x) => (x * 11.574074) / (Math.pow(10, 6)), "en": "d",
init: (x) => (x * 86400) "calc": (x) => (x * 11.574074) / (Math.pow(10, 6)),
"init": (x) => (x * 86400)
}, },
{ {
key: "h", "name": "",
unit: "h", "zh": "",
calc: (x) => (x * 277.777778) / (Math.pow(10, 6)), "en": "h",
init: (x) => (x * 3600) "calc": (x) => (x * 277.777778) / (Math.pow(10, 6)),
"init": (x) => (x * 3600)
}, },
{ {
key: "min", "name": "",
unit: "min", "zh": "",
calc: (x) => (x * 16.6666667) / 1000, "en": "min",
init: (x) => (x * 60) "calc": (x) => (x * 16.6666667) / 1000,
"init": (x) => (x * 60)
}, },
{ {
key: "s", "name": "",
unit: "s", "zh": "",
calc: (x) => (x * 1), "en": "s",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "ms", "name": "毫秒",
unit: "ms", "zh": "毫秒",
calc: (x) => (x * 1000), "en": "ms",
init: (x) => (x * 1) / 1000 "calc": (x) => (x * 1000),
"init": (x) => (x * 1) / 1000
}, },
{ {
key: "us", "name": "微秒",
unit: "μs", "zh": "微秒",
calc: (x) => (x * 1000000), "en": "μs",
init: (x) => (x * 1) / 1000000 "calc": (x) => (x * 1000000),
"init": (x) => (x * 1) / 1000000
}, },
{ {
key: "ns", "name": "纳秒",
unit: "ns", "zh": "纳秒",
calc: (x) => (x * 1000000000), "en": "ns",
init: (x) => (x * 1) / 1000000000 "calc": (x) => (x * 1000000000),
"init": (x) => (x * 1) / 1000000000
} }
], ],
special: [ "special": [
{ {
from: "h", "from": "",
to: "min", "to": "",
func: (x) => (x * 60) "func": (x) => (x * 60)
} }
], ],
group: [ "group": [
{ {
key: "", "name": "",
list: ["yr", "week", "d", "h", "min", "s", "ms", "us", "ns"] "list": [
"",
"",
"",
"",
"",
"",
"毫秒",
"微秒",
"纳秒"
]
} }
] ]
}, },
{ "speed": {
key: "speed", "name": "速度",
main: "m_s", "main": "米/秒",
unit: [ "unit": [
{ {
key: "m_s", "name": "米/秒",
unit: "m/s", "zh": "米/秒",
calc: (x) => (x * 1), "en": "m/s",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "km_s", "name": "千米/秒",
unit: "km/s", "zh": "千米/秒",
calc: (x) => (x * 1) / 1000, "en": "km/s",
init: (x) => (x * 1000) "calc": (x) => (x * 1) / 1000,
"init": (x) => (x * 1000)
}, },
{ {
key: "km_h", "name": "千米/时",
unit: "km/h", "zh": "千米/时",
calc: (x) => (x * 3.600000), "en": "km/h",
init: (x) => (x * 277.777778) / 1000 "calc": (x) => (x * 3.600000),
"init": (x) => (x * 277.777778) / 1000
}, },
{ {
key: "c", "name": "光速",
unit: "c", "zh": "光速",
calc: (x) => (x * 3.335641) / (Math.pow(10, 9)), "en": "c",
init: (x) => (x * 299792458) "calc": (x) => (x * 3.335641) / (Math.pow(10, 9)),
"init": (x) => (x * 299792458)
}, },
{ {
key: "mach", "name": "马赫",
unit: "mach", "zh": "马赫",
calc: (x) => (x * 2.938584) / 1000, "en": "mach",
init: (x) => (x * 340.300000) "calc": (x) => (x * 2.938584) / 1000,
"init": (x) => (x * 340.300000)
}, },
{ {
key: "mile_h", "name": "英里/时",
unit: "mile/h", "zh": "英里/时",
calc: (x) => (x * 2.236936), "en": "mile/h",
init: (x) => (x * 447.040000) / 1000 "calc": (x) => (x * 2.236936),
"init": (x) => (x * 447.040000) / 1000
}, },
{ {
key: "in_s", "name": "英寸/秒",
unit: "in/s", "zh": "英寸/秒",
calc: (x) => (x * 39.370079), "en": "in/s",
init: (x) => (x * 25.400000) / 1000 "calc": (x) => (x * 39.370079),
"init": (x) => (x * 25.400000) / 1000
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["m_s", "km_s", "km_h", "c", "mach", "mile_h", "in_s"] "list": [
"米/秒",
"千米/秒",
"千米/时",
"光速",
"马赫",
"英里/时",
"英寸/秒"
]
} }
] ]
}, },
{ "byte": {
key: "byte", "name": "数据存储",
main: "b", "main": "字节",
unit: [ "unit": [
{ {
key: "bit", "name": "比特",
unit: "bit", "zh": "比特",
calc: (x) => (x * 8), "en": "bit",
init: (x) => (x * 1) / 8 "calc": (x) => (x * 8),
"init": (x) => (x * 1) / 8
}, },
{ {
key: "b", "name": "字节",
unit: "b", "zh": "字节",
calc: (x) => (x * 1), "en": "b",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "kb", "name": "千字节",
unit: "kb", "zh": "千字节",
calc: (x) => (x * 1) / (Math.pow(2, 10)), "en": "kb",
init: (x) => (x * 1024) "calc": (x) => (x * 1) / (Math.pow(2, 10)),
"init": (x) => (x * 1024)
}, },
{ {
key: "mb", "name": "兆字节",
unit: "mb", "zh": "兆字节",
calc: (x) => (x * 1) / (Math.pow(2, 20)), "en": "mb",
init: (x) => (x * Math.pow(2, 20)) "calc": (x) => (x * 1) / (Math.pow(2, 20)),
"init": (x) => (x * Math.pow(2, 20))
}, },
{ {
key: "gb", "name": "千兆字节",
unit: "gb", "zh": "千兆字节",
calc: (x) => (x * 1) / (Math.pow(2, 30)), "en": "gb",
init: (x) => (x * Math.pow(2, 30)) "calc": (x) => (x * 1) / (Math.pow(2, 30)),
"init": (x) => (x * Math.pow(2, 30))
}, },
{ {
key: "tb", "name": "太字节",
unit: "tb", "zh": "太字节",
calc: (x) => (x * 1) / (Math.pow(2, 40)), "en": "tb",
init: (x) => (x * Math.pow(2, 40)) "calc": (x) => (x * 1) / (Math.pow(2, 40)),
"init": (x) => (x * Math.pow(2, 40))
}, },
{ {
key: "pb", "name": "拍字节",
unit: "pb", "zh": "拍字节",
calc: (x) => (x * 1) / (Math.pow(2, 50)), "en": "pb",
init: (x) => (x * Math.pow(2, 50)) "calc": (x) => (x * 1) / (Math.pow(2, 50)),
"init": (x) => (x * Math.pow(2, 50))
}, },
{ {
key: "eb", "name": "艾字节",
unit: "eb", "zh": "艾字节",
calc: (x) => (x * 1) / (Math.pow(2, 60)), "en": "eb",
init: (x) => (x * Math.pow(2, 60)) "calc": (x) => (x * 1) / (Math.pow(2, 60)),
"init": (x) => (x * Math.pow(2, 60))
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "", "name": "",
list: ["bit", "b", "kb", "mb", "gb", "tb", "pb", "eb"] "list": [
"比特",
"字节",
"千字节",
"兆字节",
"千兆字节",
"太字节",
"拍字节",
"艾字节"
]
} }
] ]
}, },
{ "angle": {
key: "angle", "name": "角度",
main: "degree", "main": "",
unit: [ "unit": [
{ {
key: "circle", "name": "圆周",
unit: "circle", "zh": "圆周",
calc: (x) => (x * 2.777778) / 1000, "en": "",
init: (x) => (x * 360) "calc": (x) => (x * 2.777778) / 1000,
"init": (x) => (x * 360)
}, },
{ {
key: "angle", "name": "直角",
unit: "angle", "zh": "直角",
calc: (x) => (x * 11.111111) / 1000, "en": "",
init: (x) => (x * 90) "calc": (x) => (x * 11.111111) / 1000,
"init": (x) => (x * 90)
}, },
{ {
key: "gon", "name": "百分度",
unit: "gon", "zh": "百分度",
calc: (x) => (x * 1.111111), "en": "gon",
init: (x) => (x * 900) / 1000 "calc": (x) => (x * 1.111111),
"init": (x) => (x * 900) / 1000
}, },
{ {
key: "degree", "name": "",
unit: "°", "zh": "",
calc: (x) => (x * 1), "en": "°",
init: (x) => (x * 1) "calc": (x) => (x * 1),
"init": (x) => (x * 1)
}, },
{ {
key: "min", "name": "",
unit: "", "zh": "",
calc: (x) => (x * 60), "en": "",
init: (x) => (x * 16.6666667) / 1000 "calc": (x) => (x * 60),
"init": (x) => (x * 16.6666667) / 1000
}, },
{ {
key: "s", "name": "",
unit: "'", "zh": "",
calc: (x) => (x * 3600), "en": "'",
init: (x) => (x * 0.2777778) / 1000 "calc": (x) => (x * 3600),
"init": (x) => (x * 0.2777778) / 1000
}, },
{ {
key: "rad", "name": "弧度",
unit: "rad", "zh": "弧度",
calc: (x) => (x * 17.453293) / 1000, "en": "rad",
init: (x) => (x * 57.295780) "calc": (x) => (x * 17.453293) / 1000,
"init": (x) => (x * 57.295780)
}, },
{ {
key: "mrad", "name": "毫弧度",
unit: "mrad", "zh": "毫弧度",
calc: (x) => (x * 17.453293), "en": "mrad",
init: (x) => (x * 57.295780) / 1000 "calc": (x) => (x * 17.453293),
"init": (x) => (x * 57.295780) / 1000
} }
], ],
special: [], "special": [],
group: [ "group": [
{ {
key: "angle_units", "name": "角度制",
list: ["circle", "angle", "gon", "degree", "min", "s"] "list": [
}, "圆周",
{ "直角",
key: "radian_units", "百分度",
list: ["rad", "mrad"] "",
"",
""
]
},
{
"name": "弧度制",
"list": [
"弧度",
"毫弧度"
]
} }
] ]
} },
].map((category) => { // 添加语言包 }
category['name'] = __('unit_'+category['key'])
category.unit = category.unit.map((unit) => {
unit['name'] = __(`unit_${category['key']}_${unit['key']}`)
return unit
})
category.group = category.group.map((item) => {
item['name'] = item['key'] ? __('unit_'+item['key']) : "";
return item;
})
return category;
})
const calculate = function (type, num, from, to) { /*
* 计算
* @uType String, not null, 单位类型(如length, time)
* @num Number, not null, 输入值
* @uFrom String, not null, 原单位
* @uTo String, not null, 目标单位
* @keepOrigin Boolean, null, 保持原始结果(不进行格式化),默认false
*
* return Object, 计算结果
*/
const calculate = function (type, num, from, to, keepOrigin = false) {
let fromUnit = getUnit(type, from) let fromUnit = getUnit(type, from)
if (from === to) { if (from === to) {
return format(num) return {
num: keepOrigin ? num : format(num),
unitFirst: fromUnit.zh,
unitSecond: fromUnit.en
}
} }
let toUnit = getUnit(type, to) let toUnit = getUnit(type, to)
...@@ -1246,34 +1613,33 @@ const calculate = function (type, num, from, to) { ...@@ -1246,34 +1613,33 @@ const calculate = function (type, num, from, to) {
} else { } else {
num = toUnit.calc(fromUnit.init(num)) num = toUnit.calc(fromUnit.init(num))
} }
return format(num) return {
num: keepOrigin ? num : format(num),
unitFirst: toUnit.zh,
unitSecond: toUnit.en
}
} }
const getCategory = (type) => { const getCategory = (type) => {
for (let category of CONFIG) { return CONFIG[type]
if (type === category.key) {
return category;
}
}
throw new Error(`${type} category not found`)
} }
const getUnit = (type, unitKey) => { const getUnit = (type, name) => {
let category = getCategory(type) let category = getCategory(type)
for (let unit of category.unit) { for (let i = 0; i < category.unit.length; i++) {
if (unitKey === unit.key) { if (name === category.unit[i].name) {
return unit; return category.unit[i];
} }
} }
throw new Error(`${type} - ${unitKey} unit not found`)
} }
const getSpecial = (type, from, to) => { const getSpecial = (type, from, to) => {
let category = getCategory(type) let category = getCategory(type)
if (category.special.length > 0) { if (category.special.length > 0) {
for(let special of category.special){ for (let i = 0; i < category.special.length; i++) {
if(special['from'] === from && special['to'] === to){ if (from === category.special[i].from && to === category.special[i].to) {
return special['func'] return category.special[i].func;
} }
} }
} }
...@@ -1292,7 +1658,7 @@ const format = function (num) { ...@@ -1292,7 +1658,7 @@ const format = function (num) {
if (strNum.indexOf('.') > -1) { if (strNum.indexOf('.') > -1) {
let match = strNum.match(/\.\d+e[+-](\d+)$/) let match = strNum.match(/\.\d+e[+-](\d+)$/)
if (match && match[1]) { if (match && match[1]) {
isFloat = match[1] * 1 < (MAX_NUM - 1) isFloat = match[1] * 1 < (MAX_NUM - 1) ? true : false
} else { } else {
isFloat = true isFloat = true
} }
...@@ -1349,8 +1715,37 @@ const exponential = function (num, n) { ...@@ -1349,8 +1715,37 @@ const exponential = function (num, n) {
} }
export default { export default {
CONFIG, //返回某一类的所有配置项
getCategory, getData: function (type) {
getUnit, return _.cloneDeep(getCategory(type).group).map((item) => {
calculate item.list = item.list.map((name) => {
let unit = getUnit(type, name)
return {
name,
unit: unit.zh + (unit.en ? ` (${unit.en})` : '')
}
})
return item;
})
},
getMain(type) {
return getCategory(type).main
},
//计算,返回格式化后的结果
calc: function (type, x, from, to) {
return calculate(type, x, from, to)
},
//计算,返回原始结果
calcOrigin: function (type, x, from, to) {
return calculate(type, x, from, to, true)
},
//格式化
format: function (num) {
return format(num)
},
list: () => {
return Object.keys(CONFIG).map((key) => {
return {key, name: CONFIG[key].name}
})
}
} }
<template> <template>
<div> <div>
<option-block style="text-align: center"> <option-block style="text-align: center">
<FormItem> <FormItem>
<ButtonGroup> <ButtonGroup>
<Button :type="current.type === v.key ? 'info' : 'primary'" <Button :type="current.type === v.key ? 'info' : 'primary'"
@click="handle(v.key)" @click="handle(v.key)"
v-for="v in unitLists" v-for="v in unitLists"
style="padding: 5px 10px 6px;" style="padding: 5px 10px 6px;"
:key="v.key">{{v.name}} :key="v.key">{{ v.name }}
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</FormItem> </FormItem>
</option-block> </option-block>
<option-block style="text-align: center"> <option-block style="text-align: center">
<FormItem> <FormItem>
<Input v-model="current.input" type="number"></Input> <Input v-model="current.input" type="number"></Input>
</FormItem> </FormItem>
<FormItem> <FormItem>
<Select v-model="current.from" style="width:200px"> <Select v-model="current.from" style="width:200px">
<template v-if="unitGroup[0].name !== ''"> <template v-if="unitGroup.length > 1">
<OptionGroup :label="group.name" v-for="(group,gk) in unitGroup" :key="gk"> <OptionGroup :label="group.name" v-for="(group,gk) in unitGroup" :key="gk">
<Option v-for="(unit,k) in group.list" :value="unit" :key="k">{{ unitFormat(unit) }}</Option> <Option v-for="(unit,k) in group.list" :value="unit.name" :key="k">{{ unit.unit }}</Option>
</OptionGroup> </OptionGroup>
</template> </template>
<template v-else> <template v-else>
<Option v-for="(unit,k) in unitGroup[0].list" :value="unit" :key="k">{{ unitFormat(unit) }}</Option> <Option v-for="(unit,k) in unitGroup[0].list" :value="unit.name" :key="k">{{ unit.unit }}
</template> </Option>
</Select> </template>
</FormItem> </Select>
<FormItem> </FormItem>
<Button icon="md-code-working" @click="exchange()"></Button> <FormItem>
</FormItem> <Button icon="md-code-working" @click="exchange()"></Button>
<FormItem> </FormItem>
<Select v-model="current.to" style="width:200px"> <FormItem>
<Option value="all">全部</Option> <Select v-model="current.to" style="width:200px">
<template v-if="unitGroup[0].name !== ''"> <Option value="all">全部</Option>
<OptionGroup :label="group.name" v-for="(group,gk) in unitGroup" :key="gk"> <template v-if="unitGroup.length > 1">
<Option v-for="(unit,k) in group.list" :value="unit" :key="k">{{ unitFormat(unit) }}</Option> <OptionGroup :label="group.name" v-for="(group,gk) in unitGroup" :key="gk">
</OptionGroup> <Option v-for="(unit,k) in group.list" :value="unit.name" :key="k">{{ unit.unit }}</Option>
</template> </OptionGroup>
<template v-else> </template>
<Option v-for="(unit,k) in unitGroup[0].list" :value="unit" :key="k"> <template v-else>
{{ unitFormat(unit) }} <Option v-for="(unit,k) in unitGroup[0].list" :value="unit.name" :key="k">{{ unit.unit }}
</Option> </Option>
</template> </template>
</Select> </Select>
</FormItem> </FormItem>
</option-block> </option-block>
<div v-if="isShowResult" style="padding: 0 30px"> <div v-if="isShowResult" style="padding: 0 30px">
<template v-if="current.to !== 'all' && assignResult"> <template v-if="current.to !== 'all' && assignResult">
<div style="text-align: center;margin-top: 30px;font-size: 18px;font-weight: bold"> <div style="text-align: center;margin-top: 30px;font-size: 18px;font-weight: bold">
<span style="color: red">{{current.input}}</span> {{unitFormat(current.from)}} = <span style="color: red">{{assignResult.num}}</span> <span style="color: red">{{ current.input }}</span> {{ current.from }} = <span
{{unitFormat(current.to)}} style="color: red">{{ assignResult.num }}</span>
{{ current.to }}
</div>
</template>
<CellGroup v-if="current.to === 'all'">
<Row :gutter="16">
<Col span="12" v-for="(item,k) in result" :key="k">
<Cell :title="item.num" :extra="item.unit"/>
</Col>
</Row>
</CellGroup>
</div> </div>
</template>
<CellGroup v-if="current.to === 'all'">
<Row :gutter="16">
<Col span="12" v-for="(item,k) in result" :key="k">
<Cell :title="item.num" :extra="unitFormat(item.unit)"/>
</Col>
</Row>
</CellGroup>
</div> </div>
</div>
</template> </template>
<script> <script>
import U from './library/unit' import U from './library/unit'
export default { export default {
created () { created() {
let history = this.$getToolData() let history = this.$getToolData()
this.current.type = history['type'] ? history['type'] : 'temperature' this.current.type = history['type'] ? history['type'] : 'temperature'
this.getToolData() this.getToolData()
},
computed: {
unitGroup() {
return U.getData(this.current.type)
}, },
computed: { isShowResult() {
unitGroup () { return this.current.from && this.current.type && this.current.input
return U.getData(this.current.type).group },
}, result() {
isShowResult () { let r = []
return this.current.from && this.current.type && this.current.input if (this.isShowResult) {
}, this.saveToolData()
result () { this.unitGroup.forEach((Group) => {
let r = [] Group.list.forEach((unit) => {
if (this.isShowResult) { let temp = U.calc(
this.saveToolData() this.current.type,
this.unitGroup.forEach((Group) => { this.current.input,
Group.list.forEach((unit) => { this.current.from,
let temp = U.calc( unit.name
this.current.type, )
this.current.input, r.push({
this.current.from.split('_')[0], unit: unit.name,
unit.split('_')[0] num: temp.num,
)
r.push({
unit: unit,
num: temp.num,
})
}) })
}) })
} })
return r
},
assignResult () {
if (this.current.to === 'all') {
return {}
}
let unit = this.current.to
for (let i = 0; i < this.result.length; i++) {
if (this.result[i].unit === unit) {
return this.result[i]
}
}
console.log(this.result)
console.log(unit)
console.error('无对应数据')
return null
} }
return r
}, },
methods: { assignResult() {
handle (v) { if (this.current.to === 'all') {
this.current.type = v return {}
this.getToolData() }
}, let unit = this.current.to
saveToolData () { for (let i = 0; i < this.result.length; i++) {
let history = this.$getToolData() if (this.result[i].unit === unit) {
history.type = this.current.type return this.result[i]
history.data = history.data ? history.data : {}
history.data[history.type] = {
from: this.current.from,
to: this.current.to,
input: this.current.input,
}
this.$saveToolData(history)
},
getToolData () {
let type = this.current.type
let history = this.$getToolData()
let unitHistory = history['data'] && history['data'][type] ? history['data'][type] : null
this.current.from = unitHistory ? unitHistory.from : ''
this.current.to = unitHistory ? unitHistory.to : 'all'
this.current.input = unitHistory ? unitHistory.input : ''
},
unitFormat (unit) {
return unit.split('_').join('')
},
exchange () {
if (this.current.to === 'all') {
return
}
if (!this.current.from || !this.current.to) {
return
} }
let temp = this.current.from
this.current.from = this.current.to
this.current.to = temp
} }
return null
}
},
methods: {
handle(v) {
this.current.type = v
this.getToolData()
}, },
data () { saveToolData() {
return { let history = this.$getToolData()
current: { history.type = this.current.type
type: '', history.data = history.data ? history.data : {}
from: '', history.data[history.type] = {
to: '', from: this.current.from,
input: '', to: this.current.to,
}, input: this.current.input,
unitLists: U.list,
} }
this.$saveToolData(history)
}, },
} getToolData() {
</script> let type = this.current.type
\ No newline at end of file let history = this.$getToolData()
let unitHistory = history['data'] && history['data'][type] ? history['data'][type] : null
this.current.from = unitHistory ? unitHistory.from : U.getMain(this.current.type)
this.current.to = unitHistory ? unitHistory.to : 'all'
this.current.input = unitHistory ? unitHistory.input : ''
},
exchange() {
if (this.current.to === 'all') {
return
}
if (!this.current.from || !this.current.to) {
return
}
let temp = this.current.from
this.current.from = this.current.to
this.current.to = temp
}
},
data() {
return {
current: {
type: '',
from: '',
to: '',
input: '',
},
unitLists: U.list(),
}
},
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册