From 19a11516ec4b89a77948880b70476359ccde990e Mon Sep 17 00:00:00 2001 From: Mrx <18278715334@163.com> Date: Wed, 20 May 2026 14:48:07 +0800 Subject: [PATCH] f --- src/config/toolboxRegistry.js | 658 ++++++++++++++++-------- src/pages/toolbox/query.vue | 913 +++++++++++++++++++++++++++++++--- 2 files changed, 1292 insertions(+), 279 deletions(-) diff --git a/src/config/toolboxRegistry.js b/src/config/toolboxRegistry.js index 0919176..03bdb40 100644 --- a/src/config/toolboxRegistry.js +++ b/src/config/toolboxRegistry.js @@ -336,13 +336,22 @@ export const toolboxItems = [ desc: '获取成语填空题目,猜一猜填什么字', icon: 'i-carbon-text-link', autoQuery: true, + isGame: true, // 标记为游戏类工具 fields: [], validate: () => true, validateMsg: '', resultLabels: { + diff: { label: '难度', transform: (v) => { + const map = { '1': '一般', '2': '中等', '3': '困难' } + return map[String(v)] || v + }}, question: '题目', - full: { label: '完整成语', hidden: true }, - explan: { label: '释义', hidden: true }, + correct: { label: '正确答案', hidden: true }, + wrong_a: { label: '错误选项A' }, + wrong_b: { label: '错误选项B' }, + wrong_c: { label: '错误选项C' }, + full: { label: '完整成语' }, + explan: { label: '成语解释' }, }, }, { @@ -351,16 +360,26 @@ export const toolboxItems = [ desc: '获取古诗词填空题目,考考你的诗词储备', icon: 'i-carbon-book', autoQuery: true, + isGame: true, // 标记为游戏类工具 fields: [], validate: () => true, validateMsg: '', resultLabels: { + diff: { label: '难度', transform: (v) => { + const map = { '1': '一般', '2': '中等', '3': '困难' } + return map[String(v)] || v + }}, question: '题目', - full: { label: '完整诗句', hidden: true }, + correct: { label: '正确答案', hidden: true }, + wrong_a: { label: '错误选项A' }, + wrong_b: { label: '错误选项B' }, + wrong_c: { label: '错误选项C' }, + full: { label: '完整诗句' }, + title: '诗名', author: '作者', dynasty: '朝代', - title: '诗名', category: '分类', + note: '注释', }, }, // { @@ -487,10 +506,11 @@ export const toolboxItems = [ name: '健康小妙招', desc: '提供饮食、睡眠、运动、减压等养生建议', icon: 'i-carbon-favorite', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + fields: [ + { key: 'word', label: '关键词', type: 'text', maxlength: 20, placeholder: '如:失眠、减肥、养胃' }, + ], + validate: (form) => (form.word || '').length > 0, + validateMsg: '请输入关键词', resultType: 'list', resultLabels: { content: '养生妙招', @@ -516,10 +536,11 @@ export const toolboxItems = [ { key: 'areanews', name: '地区新闻', - desc: '全国各省市地方新闻,支持按地区筛选检索', + desc: '聚合全国各省级行政区新闻资讯,支持按地区筛选与关键词检索', icon: 'i-carbon-location', fields: [ - { key: 'areaname', label: '地区名称', type: 'text', maxlength: 20, placeholder: '请输入地区名称,如:北京、上海' }, + { key: 'areaname', label: '地区名称', type: 'text', maxlength: 20, placeholder: '如:北京、上海(不带省/市)' }, + { key: 'word', label: '搜索关键词', type: 'text', maxlength: 30, placeholder: '可选,如:疫情' }, ], validate: (form) => (form.areaname || '').length > 0, validateMsg: '请输入地区名称', @@ -528,6 +549,7 @@ export const toolboxItems = [ title: '标题', source: '来源', ctime: '时间', + description: '描述', }, }, { @@ -535,16 +557,26 @@ export const toolboxItems = [ name: '元曲三百首', desc: '随机返回元曲名句,含作者、曲牌、注释、译文', icon: 'i-carbon-bookmark', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + autoQuery: false, // 需要参数,不能自动查询 + fields: [ + { key: 'num', label: '返回数量', type: 'digit', maxlength: 3, placeholder: '请输入数量(1-10)' }, + { key: 'page', label: '页码', type: 'digit', maxlength: 3, placeholder: '请输入页码' }, + { key: 'word', label: '搜索关键词', type: 'text', maxlength: 20, placeholder: '可选,如:天净沙' }, + ], + validate: (form) => { + const num = parseInt(form.num) + const page = parseInt(form.page) + return num >= 1 && num <= 10 && page >= 1 + }, + validateMsg: '请输入有效的数量(1-10)和页码(>=1)', resultType: 'list', resultLabels: { title: '曲名', author: '作者', content: '原文', note: '注释', + chapter: '章节', + translation: '译文', }, }, { @@ -567,17 +599,21 @@ export const toolboxItems = [ { key: 'zhongyao', name: '中药大全', - desc: '查询中草药别名、性味、功效、用法用量等信息', + desc: '查询近万种中草药的别名、性味、功效、主治及用法用量等信息', icon: 'i-carbon-certificate', fields: [ { key: 'word', label: '药名', type: 'text', maxlength: 20, placeholder: '请输入中药名,如:人参' }, + { key: 'num', label: '返回数量', type: 'select', mode: 'selector', options: [ + { value: '1', label: '1条' }, + { value: '5', label: '5条' }, + { value: '10', label: '10条' }, + ], default: '1' }, ], validate: (form) => (form.word || '').length > 0, validateMsg: '请输入中药名', - resultType: 'list', resultLabels: { - name: '药名', - content: '功效', + title: { label: '中药名称', priority: 1 }, + content: { label: '详细信息', priority: 2, multiline: true }, }, }, { @@ -587,6 +623,11 @@ export const toolboxItems = [ icon: 'i-carbon-hospital', fields: [ { key: 'word', label: '药品名', type: 'text', maxlength: 30, placeholder: '请输入药品名,如:阿莫西林' }, + { key: 'num', label: '返回数量', type: 'select', mode: 'selector', options: [ + { value: '10', label: '10条' }, + { value: '20', label: '20条' }, + { value: '30', label: '30条' }, + ], default: '10' }, ], validate: (form) => (form.word || '').length > 0, validateMsg: '请输入药品名', @@ -763,18 +804,28 @@ export const toolboxItems = [ }, { key: 'nutrient', - name: '营养素查询', - desc: '查询食物营养成分、功效与推荐摄入量', + name: '营养成分表', + desc: '查询近两千种食物营养成分,支持多种查询模式', icon: 'i-carbon-chart-bar', fields: [ - { key: 'word', label: '食物名称', type: 'text', maxlength: 20, placeholder: '请输入食物名,如:苹果' }, + { key: 'word', label: '关键词', type: 'text', maxlength: 20, placeholder: '食物名 如:苹果' }, + { key: 'mode', label: '查询模式', type: 'select', mode: 'selector', options: [ + { value: '0', label: '营养成分(查询具体食物)' }, + { value: '1', label: '食品分类(如:谷类、水果类)' }, + { value: '2', label: '营养正序(高到低)' }, + { value: '3', label: '营养倒序(低到高)' }, + ], default: '0' }, ], validate: (form) => (form.word || '').length > 0, - validateMsg: '请输入食物名称', + validateMsg: '请输入关键词', resultType: 'list', resultLabels: { - name: '营养素', - content: '说明', + name: '食品名称', + type: '食品种类', + rl: '热量(大卡)', + zf: '脂肪', + dbz: '蛋白质', + shhf: '碳水', }, }, { @@ -859,22 +910,27 @@ export const toolboxItems = [ price: '价格', }, }, - { - key: 'chengyujielong', - name: '成语接龙', - desc: '输入成语进行接龙游戏', - icon: 'i-carbon-link', - fields: [ - { key: 'word', label: '成语', type: 'text', maxlength: 10, placeholder: '请输入成语,如:一马当先' }, - { key: 'userid', label: '用户标识', type: 'text', maxlength: 50, placeholder: '用户唯一标识(如openid)' }, - ], - validate: (form) => (form.word || '').length > 0 && (form.userid || '').length > 0, - validateMsg: '请输入成语和用户标识', - resultLabels: { - word: '接龙成语', - state: '状态', - }, - }, + // { + // key: 'chengyujielong', + // name: '成语接龙', + // desc: '系统给出成语,你来接龙', + // icon: 'i-carbon-link', + // isGame: true, + // fields: [ + // { key: 'word', label: '接龙成语', type: 'text', maxlength: 10, placeholder: '请输入接龙的成语' }, + // ], + // validate: (form) => (form.word || '').length > 0, + // validateMsg: '请输入成语', + // resultLabels: { + // word: '接龙成语', + // state: '状态', + // pinyin: '拼音', + // jieshi: '解释', + // chuchu: '出处', + // startstr: '首字', + // endstr: '尾字', + // }, + // }, { key: 'weibohot', name: '微博热搜', @@ -915,10 +971,13 @@ export const toolboxItems = [ name: '景点查询', desc: '查询全国各地旅游景点信息', icon: 'i-carbon-location-filled', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + fields: [ + { key: 'word', label: '景点关键词', type: 'text', maxlength: 50, placeholder: '如:长城、故宫、九寨沟' }, + { key: 'city', label: '城市', type: 'text', maxlength: 30, placeholder: '如:北京、上海、杭州' }, + { key: 'province', label: '省份', type: 'text', maxlength: 30, placeholder: '如:浙江、江苏、四川,不要带末尾省' }, + ], + validate: (form) => form.word || form.city || form.province, + validateMsg: '请至少填写一个查询条件', resultType: 'list', resultLabels: { title: '景点名称', @@ -1034,9 +1093,14 @@ export const toolboxItems = [ desc: '随机返回经典诗词名句', icon: 'i-carbon-pen', autoQuery: true, - fields: [], + fields: [ + { key: 'num', label: '返回数量', type: 'digit', maxlength: 2, placeholder: '可选,数量' }, + { key: 'page', label: '页码', type: 'digit', maxlength: 3, placeholder: '可选,页码' }, + { key: 'word', label: '搜索关键词', type: 'text', maxlength: 20, placeholder: '可选,如:明月' }, + ], validate: () => true, validateMsg: '', + resultType: 'list', resultLabels: { content: '诗句', author: '作者', @@ -1045,11 +1109,12 @@ export const toolboxItems = [ }, { key: 'lunar', - name: '农历查询', + name: '老黄历', desc: '查询中国老黄历信息', icon: 'i-carbon-calendar', - autoQuery: true, - fields: [], + fields: [ + { key: 'date', label: '查询日期', type: 'date', placeholder: '请选择日期' }, + ], validate: () => true, validateMsg: '', resultLabels: { @@ -1058,6 +1123,12 @@ export const toolboxItems = [ shengxiao: '生肖', fitness: '宜', taboo: '忌', + chongsha: '冲煞', + shenwei: '神位', + taishen: '胎神', + lunar_festival: '农历节日', + festival: '公历节日', + jieqi: '节气', }, }, { @@ -1147,14 +1218,34 @@ export const toolboxItems = [ icon: 'i-carbon-book', fields: [ { key: 'word', label: '成语', type: 'text', maxlength: 10, placeholder: '请输入成语,如:一帆风顺' }, + { key: 'num', label: '返回数量', type: 'select', mode: 'selector', options: [ + { value: '10', label: '10条' }, + { value: '20', label: '20条' }, + { value: '30', label: '30条' }, + { value: '50', label: '50条' }, + ], default: '10' }, + { key: 'mode', label: '搜索模式', type: 'select', mode: 'selector', options: [ + { value: '0', label: '默认(包含)' }, + { value: '1', label: '精确(相等)' }, + { value: '2', label: '前缀(开头)' }, + ], default: '0' }, + { key: 'page', label: '页码', type: 'select', mode: 'selector', options: [ + { value: '1', label: '第1页' }, + { value: '2', label: '第2页' }, + { value: '3', label: '第3页' }, + { value: '4', label: '第4页' }, + { value: '5', label: '第5页' }, + ], default: '1' }, ], validate: (form) => (form.word || '').length > 0, validateMsg: '请输入成语', resultType: 'list', resultLabels: { - name: '成语', + chengyu: '成语', pinyin: '拼音', - content: '释义', + diangu: '典故', + chuchu: '出处', + fanli: '范例', }, }, { @@ -1178,17 +1269,38 @@ export const toolboxItems = [ desc: '根据生日查询性格与命运分析', icon: 'i-carbon-event', fields: [ - { key: 'm', label: '月份(1-12)', type: 'digit', maxlength: 2, placeholder: '请输入月份' }, - { key: 'd', label: '日期(1-31)', type: 'digit', maxlength: 2, placeholder: '请输入日期' }, + { key: 'm', label: '月份', type: 'select', mode: 'selector', options: [ + { value: '1', label: '1月' }, { value: '2', label: '2月' }, + { value: '3', label: '3月' }, { value: '4', label: '4月' }, + { value: '5', label: '5月' }, { value: '6', label: '6月' }, + { value: '7', label: '7月' }, { value: '8', label: '8月' }, + { value: '9', label: '9月' }, { value: '10', label: '10月' }, + { value: '11', label: '11月' }, { value: '12', label: '12月' }, + ] }, + { key: 'd', label: '日期', type: 'select', mode: 'selector', options: [ + { value: '1', label: '1日' }, { value: '2', label: '2日' }, + { value: '3', label: '3日' }, { value: '4', label: '4日' }, + { value: '5', label: '5日' }, { value: '6', label: '6日' }, + { value: '7', label: '7日' }, { value: '8', label: '8日' }, + { value: '9', label: '9日' }, { value: '10', label: '10日' }, + { value: '11', label: '11日' }, { value: '12', label: '12日' }, + { value: '13', label: '13日' }, { value: '14', label: '14日' }, + { value: '15', label: '15日' }, { value: '16', label: '16日' }, + { value: '17', label: '17日' }, { value: '18', label: '18日' }, + { value: '19', label: '19日' }, { value: '20', label: '20日' }, + { value: '21', label: '21日' }, { value: '22', label: '22日' }, + { value: '23', label: '23日' }, { value: '24', label: '24日' }, + { value: '25', label: '25日' }, { value: '26', label: '26日' }, + { value: '27', label: '27日' }, { value: '28', label: '28日' }, + { value: '29', label: '29日' }, { value: '30', label: '30日' }, + { value: '31', label: '31日' }, + ] }, ], - validate: (form) => { - const m = parseInt(form.m) - const d = parseInt(form.d) - return m >= 1 && m <= 12 && d >= 1 && d <= 31 - }, - validateMsg: '请输入有效的月份(1-12)和日期(1-31)', + validate: (form) => (form.m || '').length > 0 && (form.d || '').length > 0, + validateMsg: '请选择月份和日期', resultLabels: { - content: '性格分析', + title: '性格标题', + content: '详细分析', }, }, { @@ -1234,8 +1346,12 @@ export const toolboxItems = [ validateMsg: '', resultType: 'list', resultLabels: { - title: '菜名', - content: '做法', + cp_name: '菜名', + type_name: '类型', + yuanliao: '原料', + tiaoliao: '调料', + zuofa: '做法', + tishi: '提示', }, }, { @@ -1257,7 +1373,7 @@ export const toolboxItems = [ { key: 'constellation', name: '星座运势', - desc: '查询十二星座今日/明日/本周/月度运势', + desc: '查询十二星座今日运势,含爱情、工作、幸运色等指数', icon: 'i-carbon-star-filled', fields: [ { key: 'astro', label: '星座', type: 'select', mode: 'selector', options: [ @@ -1268,52 +1384,49 @@ export const toolboxItems = [ { value: '射手座', label: '射手座' }, { value: '摩羯座', label: '摩羯座' }, { value: '水瓶座', label: '水瓶座' }, { value: '双鱼座', label: '双鱼座' }, ] }, - { key: 'fortune', label: '运势类型', type: 'select', mode: 'selector', options: [ - { value: 'today', label: '今日' }, { value: 'tomorrow', label: '明日' }, - { value: 'week', label: '本周' }, { value: 'month', label: '本月' }, - ], default: 'today' }, ], validate: (form) => (form.astro || '').length > 0, validateMsg: '请选择星座', resultLabels: { astro: '星座', - summary: '综合运势', - love: '爱情运', - work: '事业运', - money: '财运', - health: '健康运', - }, - }, - { - key: 'fanyi', - name: '在线翻译', - desc: '支持多语种互译,自动识别源语言', - icon: 'i-carbon-translate', - fields: [ - { key: 'content', label: '待翻译文本', type: 'textarea', placeholder: '请输入要翻译的文本' }, - ], - validate: (form) => (form.content || '').length > 0, - validateMsg: '请输入要翻译的文本', - resultLabels: { - content: '原文', - result: '译文', - from: '源语言', - to: '目标语言', + summary: '综合指数', + love: '爱情指数', + work: '工作指数', + money: '财运指数', + health: '健康指数', + color: '幸运颜色', + number: '幸运数字', + qfriend: '贵人星座', + today_summary: '今日概述', }, }, + // { + // key: 'fanyi', + // name: '在线翻译', + // desc: '支持多语种互译,自动识别源语言', + // icon: 'i-carbon-translate', + // fields: [ + // { key: 'content', label: '待翻译文本', type: 'textarea', placeholder: '请输入要翻译的文本' }, + // ], + // validate: (form) => (form.content || '').length > 0, + // validateMsg: '请输入要翻译的文本', + // resultLabels: { + // content: '原文', + // result: '译文', + // from: '源语言', + // to: '目标语言', + // }, + // }, { key: 'holiday', name: '节假日查询', - desc: '查询指定日期是否为节假日、调休日或工作日', + desc: '查询当年某日期是否为节假日、调休日或工作日', icon: 'i-carbon-calendar', fields: [ - { key: 'date', label: '查询日期', type: 'text', maxlength: 30, placeholder: '如:2025-01-01 或 2025-10,留空查今天' }, - { key: 'type', label: '查询方式', type: 'radio', options: [ - { value: 0, label: '批量查询' }, - { value: 1, label: '按年' }, - { value: 2, label: '按月' }, - { value: 3, label: '按范围' }, - ], default: 0 }, + { key: 'type', label: '选项', type: 'radio', options: [ + { value: 1, label: '今年' }, + { value: 2, label: '今月' }, + ], default: 1 }, ], validate: () => true, validateMsg: '', @@ -1423,39 +1536,48 @@ export const toolboxItems = [ validateMsg: '请输入汉字', resultLabels: { word: '汉字', - pinyin: '拼音', content: '说明', }, }, - { - key: 'hanzipinyin', - name: '汉字拼音', - desc: '汉字拼音查询', - icon: 'i-carbon-text-font', - fields: [ - { key: 'text', label: '汉字', type: 'textarea', placeholder: '请输入要查询的汉字' }, - ], - validate: (form) => (form.text || '').length > 0, - validateMsg: '请输入要查询的汉字', - resultLabels: { - text: '原文', - pinyin: '拼音', - }, - }, + { key: 'chaizi', name: '汉字拆解', desc: '查询汉字的拆字结构及含义', icon: 'i-carbon-text-creation', fields: [ - { key: 'word', label: '汉字', type: 'text', maxlength: 1, placeholder: '请输入一个汉字' }, + { key: 'type', label: '查询方式', type: 'radio', options: [ + { value: 1, label: '拆字' }, + { value: 0, label: '合体' }, + ], default: 0 }, + { key: 'word', label: '查询内容', type: 'text', maxlength: 50, placeholder: '请输入一个汉字' }, ], validate: (form) => (form.word || '').length > 0, - validateMsg: '请输入汉字', + validateMsg: '请输入查询内容', resultLabels: { word: '汉字', content: '拆解', }, + fieldVisibility: { + word: (form) => { + if (form.type === 1) { + // 拆字模式:单个汉字 + return true + } else { + // 合体模式:部首空格分隔 + return true + } + }, + }, + fieldPlaceholder: { + word: (form) => { + if (form.type === 1) { + return '请输入一个汉字' + } else { + return '请输入完整部首(空格分隔),如:山 合' + } + }, + }, }, { key: 'xhzd', @@ -1467,22 +1589,34 @@ export const toolboxItems = [ ], validate: (form) => (form.word || '').length > 0, validateMsg: '请输入汉字', + resultType: 'dict', resultLabels: { - word: '汉字', - content: '释义', + word: { label: '汉字', priority: 1 }, + py: { label: '拼音', priority: 2 }, + pyyb: { label: '拼音音标', priority: 3 }, + wubi: { label: '五笔', priority: 4 }, + bihua: { label: '笔画', priority: 5 }, + bushou: { label: '部首', priority: 6 }, + bishun: { label: '笔顺', priority: 7 }, + content: { label: '释义', priority: 8, multiline: true }, + explain: { label: '详细解释', priority: 9, multiline: true }, }, }, { key: 'dailytel', - name: '每日一句', - desc: '每日一句励志语录', - icon: 'i-carbon-quote', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + name: '全国常用电话', + desc: '查询全国常用电话号码', + icon: 'i-carbon-phone-filled', + fields: [ + { key: 'word', label: '机构名称或电话', type: 'text', maxlength: 50, placeholder: '请输入机构名称或电话号码' }, + ], + validate: (form) => (form.word || '').length > 0, + validateMsg: '请输入机构名称或电话号码', + resultType: 'list', resultLabels: { - content: '语录', + name: '机构名称', + cate: '分类', + tel: '电话', }, }, { @@ -1664,13 +1798,30 @@ export const toolboxItems = [ name: '宋词', desc: '宋词原文及赏析', icon: 'i-carbon-book', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + autoQuery: true, // 有默认值,可以自动查询 + fields: [ + { key: 'num', label: '返回数量', type: 'digit', maxlength: 2, placeholder: '可选,1-10,默认1' }, + { key: 'page', label: '页码', type: 'digit', maxlength: 3, placeholder: '可选,默认1' }, + { key: 'word', label: '搜索关键词', type: 'text', maxlength: 20, placeholder: '可选,如:水调歌头' }, + ], + validate: (form) => { + // num 和 page 都有默认值,所以不填也可以 + if (form.num && (parseInt(form.num) < 1 || parseInt(form.num) > 10)) { + return false + } + if (form.page && parseInt(form.page) < 1) { + return false + } + return true + }, + validateMsg: '数量必须在1-10之间,页码必须>=1', + resultType: 'list', resultLabels: { title: '词牌', + author: '作者', content: '原文', + translate: '译文', + tags: '标签', }, }, { @@ -1679,26 +1830,33 @@ export const toolboxItems = [ desc: '《诗经》原文及释义', icon: 'i-carbon-book', autoQuery: true, - fields: [], + fields: [ + { key: 'num', label: '返回数量', type: 'digit', maxlength: 2, placeholder: '可选,1-10,默认10' }, + { key: 'word', label: '搜索关键词', type: 'text', maxlength: 20, placeholder: '可选,如:关雎' }, + ], validate: () => true, validateMsg: '', + resultType: 'list', resultLabels: { - title: '篇名', + name: '篇名', + author: '作者', content: '原文', + note: '注释', }, }, { key: 'duishici', name: '对诗词', - desc: '诗词对仗游戏', + desc: '填对诗词挑战,随机提供诗词上句,用户填写下句', icon: 'i-carbon-text-link', - fields: [ - { key: 'word', label: '关键词', type: 'text', maxlength: 20, placeholder: '请输入关键词' }, - ], - validate: (form) => (form.word || '').length > 0, - validateMsg: '请输入关键词', + autoQuery: true, + fields: [], + validate: () => true, + validateMsg: '', resultLabels: { - content: '诗词', + quest: '前半句', + answer: { label: '后半句', hidden: true }, + source: '出处', }, }, { @@ -1716,18 +1874,19 @@ export const toolboxItems = [ }, { key: 'msdl', - name: '民乐歌词', - desc: '中国传统民乐歌词查询', - icon: 'i-carbon-microphone', - fields: [ - { key: 'word', label: '关键词', type: 'text', maxlength: 20, placeholder: '请输入关键词' }, - ], - validate: (form) => (form.word || '').length > 0, - validateMsg: '请输入关键词', + name: '民俗对联', + desc: '春联、乔迁、开业、结婚等民俗对联查询', + icon: 'i-carbon-text-link', + autoQuery: true, + fields: [], + validate: () => true, + validateMsg: '', resultType: 'list', resultLabels: { - title: '歌名', - content: '歌词', + fenlei: '分类', + hengpi: '横批', + shanglian: '上联', + xialian: '下联', }, }, { @@ -1747,13 +1906,43 @@ export const toolboxItems = [ }, { key: 'flmj', - name: '法律名句', - desc: '法律法规经典名言', + name: '分类名句', + desc: '按分类查询古诗词中的经典名句', icon: 'i-carbon-document', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + fields: [ + { + key: 'type', + label: '分类类型', + type: 'select', + mode: 'selector', + options: [ + { value: '经典', label: '经典' }, + { value: '春天', label: '春天' }, + { value: '夏天', label: '夏天' }, + { value: '秋天', label: '秋天' }, + { value: '冬天', label: '冬天' }, + { value: '写雨', label: '写雨' }, + { value: '写雪', label: '写雪' }, + { value: '写风', label: '写风' }, + { value: '写花', label: '写花' }, + { value: '写鸟', label: '写鸟' }, + { value: '写山', label: '写山' }, + { value: '写水', label: '写水' }, + { value: '亲情', label: '亲情' }, + { value: '爱情', label: '爱情' }, + { value: '友情', label: '友情' }, + { value: '爱国', label: '爱国' }, + { value: '春节', label: '春节' }, + { value: '元宵', label: '元宵' }, + { value: '端午', label: '端午' }, + { value: '七夕', label: '七夕' }, + { value: '中秋', label: '中秋' }, + { value: '重阳', label: '重阳' }, + ], + }, + ], + validate: (form) => (form.type || '').length > 0, + validateMsg: '请选择分类类型', resultLabels: { content: '名句', source: '出处', @@ -1761,22 +1950,23 @@ export const toolboxItems = [ }, { key: 'targa', - name: '塔罗牌', - desc: '塔罗牌占卜解读', - icon: 'i-carbon-star', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + name: '扩展名查询', + desc: '解析常见文件后缀的格式类型与用途说明', + icon: 'i-carbon-document', + fields: [ + { key: 'word', label: '文件后缀', type: 'text', maxlength: 20, placeholder: '如:apk、pdf、mp4' }, + ], + validate: (form) => (form.word || '').length > 0, + validateMsg: '请输入文件后缀名', resultLabels: { - targa: '牌面', - notes: '解读', + targa: '扩展名', + notes: '含义说明', }, }, { key: 'wxhottopic', - name: '微信热点', - desc: '获取微信实时热点话题', + name: '腾讯热点', + desc: '实时抓取腾讯新闻及微信生态热点话题榜单,每10-30分钟更新一次', icon: 'i-carbon-chart-line', autoQuery: true, fields: [], @@ -1784,15 +1974,14 @@ export const toolboxItems = [ validateMsg: '', resultType: 'list', resultLabels: { - title: '标题', - content: '内容', - index: '热度', + word: '话题', + index: '排序', }, }, { key: 'douyinhot', name: '抖音热搜', - desc: '获取抖音实时热搜榜单', + desc: '实时抓取抖音App热门搜索榜单,返回50条热点视频话题及热度排名', icon: 'i-carbon-chart-line', autoQuery: true, fields: [], @@ -1800,22 +1989,22 @@ export const toolboxItems = [ validateMsg: '', resultType: 'list', resultLabels: { - title: '标题', - content: '内容', - index: '热度', + word: '话题', + label_text: '标签', + hotindex: '热度指数', }, }, { key: 'hotreview', - name: '热点评论', - desc: '热点事件网友评论', + name: '云音乐热评', + desc: '云音乐网友热评', icon: 'i-carbon-chat', autoQuery: true, fields: [], validate: () => true, validateMsg: '', - resultType: 'list', resultLabels: { + source: '来源', content: '评论', }, }, @@ -1835,16 +2024,15 @@ export const toolboxItems = [ }, { key: 'hsjz', - name: '黄氏简码', - desc: '黄氏简码输入法查询', - icon: 'i-carbon-keyboard', - fields: [ - { key: 'word', label: '字', type: 'text', maxlength: 1, placeholder: '请输入汉字' }, - ], - validate: (form) => (form.word || '').length > 0, - validateMsg: '请输入汉字', + name: '失恋分手句子', + desc: '随机返回失恋分手相关的经典句子', + icon: 'i-carbon-face-pained', + autoQuery: true, + fields: [], + validate: () => true, + validateMsg: '', resultLabels: { - content: '简码内容', + content: '句子', }, }, { @@ -1863,15 +2051,24 @@ export const toolboxItems = [ }, { key: 'cnmoney', - name: '人民币', - desc: '人民币面额、图案、防伪特征', + name: '金额转大写', + desc: '阿拉伯数字转中文大写、英文大写、财务简写', icon: 'i-carbon-money', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', + fields: [ + { key: 'money', label: '金额', type: 'text', maxlength: 20, placeholder: '请输入金额' }, + { key: 'type', label: '单位类型', type: 'select', mode: 'selector', options: [ + { value: 'usd', label: '美元-元(默认)' }, + { value: 'usd_1', label: '美元-分' }, + { value: 'rmb', label: '人民币-元' }, + { value: 'rmb_1', label: '人民币-分' }, + ], default: 'usd' }, + ], + validate: (form) => (form.money || '').length > 0, + validateMsg: '请输入金额', resultLabels: { - content: '人民币信息', + cnresult: '中文大写', + enresult: '英文大写', + fnresult: '财务简写', }, }, { @@ -1892,15 +2089,21 @@ export const toolboxItems = [ { key: 'baiketiku', name: '百科题库', - desc: '百科知识问答题库', + desc: '随机返回一道生活百科问答题,覆盖科学、健康、安全、常识等实用知识', icon: 'i-carbon-help', autoQuery: true, + isGame: true, fields: [], validate: () => true, validateMsg: '', resultLabels: { - quest: '问题', - result: '答案', + title: { label: '问题', multiline: true }, + answer: { label: '正确答案', hidden: true }, + answerA: { label: 'A', transform: (v) => v || '' }, + answerB: { label: 'B', transform: (v) => v || '' }, + answerC: { label: 'C', transform: (v) => v || '' }, + answerD: { label: 'D', transform: (v) => v || '' }, + analytic: { label: '解析', hidden: true }, }, }, { @@ -1933,19 +2136,19 @@ export const toolboxItems = [ content: '日记', }, }, - { - key: 'robotlog', - name: '机器人日志', - desc: '机器人运行日志查询', - icon: 'i-carbon-idea', - autoQuery: true, - fields: [], - validate: () => true, - validateMsg: '', - resultLabels: { - content: '日志', - }, - }, + // { + // key: 'robotlog', + // name: '机器人日志', + // desc: '机器人运行日志查询', + // icon: 'i-carbon-idea', + // autoQuery: true, + // fields: [], + // validate: () => true, + // validateMsg: '', + // resultLabels: { + // content: '日志', + // }, + // }, { key: 'aqi', name: '空气质量', @@ -1969,17 +2172,44 @@ export const toolboxItems = [ { key: 'pet', name: '宠物百科', - desc: '宠物饲养知识大全', + desc: '猫、犬、爬宠、水族等宠物的生活习性、喂养方法、价格及图片', icon: 'i-carbon-paw', fields: [ - { key: 'name', label: '宠物名', type: 'text', maxlength: 20, placeholder: '请输入宠物名称' }, + { key: 'name', label: '宠物名称', type: 'text', maxlength: 20, placeholder: '如:哈士奇、波斯猫' }, + { key: 'type', label: '宠物类型', type: 'select', mode: 'selector', options: [ + { value: '', label: '全部类型' }, + { value: '0', label: '猫科' }, + { value: '1', label: '犬类' }, + { value: '2', label: '爬行类' }, + { value: '3', label: '小宠物类' }, + { value: '4', label: '水族类' }, + ], default: '' }, + { key: 'num', label: '每页数量', type: 'select', mode: 'selector', options: [ + { value: '5', label: '5条' }, + { value: '10', label: '10条' }, + { value: '20', label: '20条' }, + ], default: '10' }, ], - validate: (form) => (form.name || '').length > 0, - validateMsg: '请输入宠物名称', + validate: () => true, // 所有字段都是可选的 + validateMsg: '', resultType: 'list', resultLabels: { - name: '宠物', - content: '知识', + name: '宠物名称', + engName: '英文名', + pettype: { label: '类型', transform: (v) => { + const map = { 0: '猫科', 1: '犬类', 2: '爬行类', 3: '小宠物类', 4: '水族类' } + return map[String(v)] || v + }}, + nation: '祖籍', + life: '寿命', + price: '价格', + characters: '性格特点', + feature: '体态特征', + characterFeature: '特点描述', + feedPoints: '喂养注意', + careKnowledge: '照顾须知', + easyOfDisease: '易患病', + desc: '描述', }, }, { @@ -2015,13 +2245,12 @@ export const toolboxItems = [ { key: 'zaowanwords', name: '早安晚安语', - desc: '适合发朋友圈的早安晚安文案', + desc: '适合发朋友圈的早安晚安文案,不定期更新', icon: 'i-carbon-sun', autoQuery: true, fields: [], validate: () => true, validateMsg: '', - resultType: 'list', resultLabels: { content: '文案', }, @@ -2035,7 +2264,6 @@ export const toolboxItems = [ fields: [], validate: () => true, validateMsg: '', - resultType: 'list', resultLabels: { content: '问候语', }, diff --git a/src/pages/toolbox/query.vue b/src/pages/toolbox/query.vue index 4c9f6ad..39ffa3b 100644 --- a/src/pages/toolbox/query.vue +++ b/src/pages/toolbox/query.vue @@ -22,6 +22,14 @@ const loading = ref(false) const result = ref | null>(null) const error = ref('') +// 游戏相关状态 +const gameOptions = ref>([]) +const selectedOption = ref(null) +const answered = ref(false) +const answeredCorrect = ref(false) +const systemIdiom = ref('') // 系统给出的成语 +const chainGameStep = ref(0) // 接龙游戏步骤:0=初始,1=用户输入 + // 选择框相关状态 const popup = ref(null) const currentField = ref(null) @@ -32,6 +40,7 @@ onLoad((query) => { const key = (query?.key as string) || '' toolKey.value = key tool.value = getToolboxItem(key) + console.log('工具配置:', tool.value) if (!tool.value) { error.value = '未找到该工具' } @@ -41,10 +50,24 @@ onLoad((query) => { // 初始化表单默认值 if (tool.value.fields) { tool.value.fields.forEach(field => { + // 设置默认值 if (field.default !== undefined && !form.value[field.key]) { form.value[field.key] = field.default } + // 对于 select 类型,即使没有值也设置默认值 + if (field.type === 'select' && !form.value[field.key] && field.default !== undefined) { + form.value[field.key] = field.default + } + // 如果是日期字段且没有默认值,设置为今天 + if (field.type === 'date' && !form.value[field.key]) { + const today = new Date() + const year = today.getFullYear() + const month = String(today.getMonth() + 1).padStart(2, '0') + const day = String(today.getDate()).padStart(2, '0') + form.value[field.key] = `${year}-${month}-${day}` + } }) + console.log('初始化后的表单:', JSON.stringify(form.value)) } // 如果工具标记了自动查询或不需要输入参数,打开即查 @@ -73,6 +96,70 @@ function getSelectedLabel(field, value) { return option ? option.label : null } +// 判断字段是否可见 +function isFieldVisible(field, formValue) { + if (!tool.value?.fieldVisibility || !field.key) { + return true + } + const visibilityFn = tool.value.fieldVisibility[field.key] + if (visibilityFn && typeof visibilityFn === 'function') { + return visibilityFn(formValue) + } + return true +} + +// 获取动态placeholder +function getFieldPlaceholder(field) { + if (!tool.value?.fieldPlaceholder || !field.key) { + return field.placeholder || '' + } + const placeholderFn = tool.value.fieldPlaceholder[field.key] + if (placeholderFn && typeof placeholderFn === 'function') { + return placeholderFn(form.value) + } + return field.placeholder || '' +} + +// 处理单选按钮切换 +function handleRadioChange(fieldKey: string, value: any) { + form.value[fieldKey] = value + // 清空依赖该字段的其他字段值 + if (tool.value?.fieldVisibility) { + Object.keys(tool.value.fieldVisibility).forEach(key => { + const visibilityFn = tool.value.fieldVisibility[key] + if (visibilityFn && !visibilityFn(form.value)) { + form.value[key] = '' + } + }) + } + // 清空word字段的值 + if (fieldKey === 'type') { + form.value['word'] = '' + } +} + +// 获取显示值(支持 transform) +function getDisplayValue(key: string, value: any) { + if (!tool.value?.resultLabels) + return value + + const labelOrObj = tool.value.resultLabels[key] + if (typeof labelOrObj === 'object' && labelOrObj !== null && labelOrObj.transform) { + return labelOrObj.transform(value) + } + return value +} + +// 处理输入框输入,自动截断 +function handleInput(fieldKey: string, value: string) { + form.value[fieldKey] = value + // 如果有maxlength限制,自动截断 + const field = tool.value?.fields?.find(f => f.key === fieldKey) + if (field?.maxlength && value.length > field.maxlength) { + form.value[fieldKey] = value.substring(0, field.maxlength) + } +} + // 显示自定义选择器 function showPicker(field) { currentField.value = field @@ -106,9 +193,49 @@ async function handleQuery() { return error.value = '' + answered.value = false + + // 成语接龙特殊处理 + if (toolKey.value === 'chengyujielong') { + if (!form.value.word) { + error.value = '请输入成语' + return + } + + loading.value = true + try { + const res = await postToolboxQuery(toolKey.value, { + word: form.value.word, + userid: '1212' // 固定用户ID + }) + + if (res.code === 200 && res.data?.result) { + result.value = res.data.result + answered.value = true // 标记已回答 + + // 如果接龙成功,保存系统返回的成语 + if (res.data.result.word) { + systemIdiom.value = res.data.result.word + chainGameStep.value = 1 + } + } else { + error.value = res.msg || '接龙失败' + } + } catch { + error.value = '网络错误,请稍后重试' + } finally { + loading.value = false + } + return + } + result.value = null revealedKeys.value = new Set() + // 调试:打印表单值 + console.log('提交的表单数据:', JSON.stringify(form.value)) + console.log('验证结果:', tool.value.validate(form.value)) + if (!tool.value.validate(form.value)) { error.value = tool.value.validateMsg return @@ -119,6 +246,21 @@ async function handleQuery() { const res = await postToolboxQuery(toolKey.value, form.value) if (res.code === 200 && res.data?.result) { result.value = res.data.result + + // 如果是游戏类工具 + if (tool.value?.isGame) { + // 成语填字和诗词填空:准备选项 + if (toolKey.value === 'idiom-quiz' || toolKey.value === 'poem-fill') { + prepareGameOptions() + } + // 成语接龙:记录系统返回的成语 + if (toolKey.value === 'chengyujielong') { + if (result.value?.word) { + systemIdiom.value = result.value.word + chainGameStep.value = 1 + } + } + } } else { error.value = res.msg || '查询失败' @@ -187,6 +329,71 @@ const listLabelEntries = computed(() => { return [] return Object.entries(tool.value.resultLabels) }) + +// 游戏工具:准备选项(打乱顺序) +const prepareGameOptions = () => { + if (!result.value || !result.value.correct) + return + + const correct = result.value.correct + const options = [ + { label: correct, value: correct, isCorrect: true }, + { label: result.value.wrong_a || '', value: result.value.wrong_a || '', isCorrect: false }, + { label: result.value.wrong_b || '', value: result.value.wrong_b || '', isCorrect: false }, + { label: result.value.wrong_c || '', value: result.value.wrong_c || '', isCorrect: false }, + ].filter(opt => opt.label) // 过滤空值 + + // 打乱顺序 + for (let i = options.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[options[i], options[j]] = [options[j], options[i]] + } + + gameOptions.value = options + selectedOption.value = null + answered.value = false +} + +// 点击选项 +function handleOptionClick(option: { label: string; value: string; isCorrect: boolean }) { + if (answered.value) + return + + selectedOption.value = option.value + answered.value = true + answeredCorrect.value = option.isCorrect + + // 如果答对了,显示完整答案和解释 + if (option.isCorrect) { + revealedKeys.value.add('full') + revealedKeys.value.add('explan') + } +} + +// 快速填入:将系统接龙的成语填入输入框 +function handleQuickFill() { + if (result.value?.word) { + form.value.word = result.value.word + systemIdiom.value = result.value.word + // 清空之前的结果 + result.value = null + answered.value = false + } +} + +// 重新开始(再来一题) +function handleRestart() { + if (toolKey.value === 'chengyujielong') { + // 成语接龙:清空表单,重新开局 + form.value.word = '' + systemIdiom.value = '' + chainGameStep.value = 0 + answered.value = false + result.value = null + return + } + handleQuery() +}