当前位置: 首页 > news >正文

代码统计网站突发大事震惊全国

代码统计网站,突发大事震惊全国,并且图片越大越好,网站qq启动链接怎么做HBuilderx 插件开发变量名称翻译 ,中文转(小驼峰,大驼峰,下划线,常量,CSS类名) 插件开发文档 工具HBuilderx ,创建项目 创建成功后目录 插件需求 开发时 用来将中文转为&#xff0…

HBuilderx 插件开发变量名称翻译 ,中文转(小驼峰,大驼峰,下划线,常量,CSS类名)

插件开发文档
工具HBuilderx ,创建项目

在这里插入图片描述
在这里插入图片描述

创建成功后目录

在这里插入图片描述

插件需求 开发时 用来将中文转为(小驼峰,大驼峰,下划线,常量,CSS类名)
  1. package.json 文件中配置插件菜单,通过在插件package.json文件中contributes节点下定义的一些JSON格式的配置项。(注意:配置时一定要注意json格式)
{"id": "plugin-fyi","name": "fyi","description": "plugin-fyi","displayName": "plugin-fyi","version": "0.0.0","publisher": "your name","engines": {"HBuilderX": "^2.7.0"},"categories": ["Other"],"main": "./extension","activationEvents": ["*"],"contributes": {"commands": [{"command": "fyi.smallHump","title": "小驼峰"},{"command": "fyi.bigHump","title": "大驼峰"},{"command": "fyi.underline","title": "下划线"},{"command": "fyi.constant","title": "常量"},{"command": "fyi.cssClassName","title": "CSS类名"}],"menus": {"editor/context": [{"group": "z_commands"}, {"title": "小驼峰","command": "fyi.smallHump","group": "z_commands"},{"title": "大驼峰","command": "fyi.bigHump","group": "z_commands"},{"title": "下划线","command": "fyi.underline","group": "z_commands"},{"title": "常量","command": "fyi.constant","group": "z_commands"},{"title": "CSS类名","command": "fyi.cssClassName","group": "z_commands"},{"group": "z_commands"}]},"extensionDependencies": ["plugin-manager"]},"dependencies": {"axios": "^1.7.9","js-md5": "^0.8.3"}
}
  1. 运行插件
    在这里插入图片描述
  2. 运行成功 会打开新的编辑器
    在这里插入图片描述
  3. 打开一个项目 或者新建一个项目 (我这里是打开一个项目)然后右键查看
    在这里插入图片描述
中文翻译需要用到 百度翻译
  1. 百度翻译开放平台
    在这里插入图片描述
  2. 申请秘钥 APPID密钥
    在这里插入图片描述
开始添加逻辑处理
  1. 新建js文件夹 用来处理 翻译 转换的逻辑

  2. 在这里插入图片描述

  3. extension.js 文件 该文件为主文件 需要与 package.json 中的 main 保持一致

	const hx = require("hbuilderx");const commands = require('./js/index')//该方法将在插件激活的时候调用function activate(context) {for (const c of commands) {//订阅销毁钩子,插件禁用的时候,自动注销该command。context.subscriptions.push(c);}}//该方法将在插件禁用的时候调用(目前是在插件卸载的时候触发)function deactivate() {}module.exports = {activate,deactivate}
  1. 调用百度翻译需要用到 axiosMD5.js 安装:
npm install axios
npm install js-md5 
  1. util.js 调用百度api 翻译 *******请更换代码中的 appid 和密钥********
const axios = require('axios');
const hx = require("hbuilderx");
const md5 = require('js-md5');// 封装百度翻译 API 请求函数
module.exports = async function (text) {try {// 在状态栏显示正在转换的消息hx.window.setStatusBarMessage(`正在转换...`);// 百度翻译 API 的配置信息const appid = '你上面申请的appid';const secretKey = '你上面申请的密钥';// 生成随机数 saltconst salt = Math.floor(Math.random() * (65536 - 32768 + 1)) + 32768;// 拼接用于生成签名的字符串const signStr = appid + text + salt + secretKey;// 计算 MD5 哈希值作为签名const sign = md5(signStr);// 发送请求到百度翻译 APIconst response = await axios({method: 'post',url: 'http://api.fanyi.baidu.com/api/trans/vip/translate',data: {q: text,from: 'auto',to: 'en',appid: appid,salt: salt,sign: sign},headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }});const data = response.data;// 检查响应数据是否包含必要的字段if (data.from && data.to && data.trans_result) {// 解析出翻译结果return data.trans_result[0].dst;} else {// 处理识别失败的情况const errorMessage = `识别失败,错误码: ${data.error_code}`;hx.window.showErrorMessage(errorMessage);return {msg: "识别失败",code: data.error_code};}} catch (error) {// 处理请求过程中可能出现的错误const errorMessage = `请求翻译 API 时发生错误: ${error.message}`;hx.window.showErrorMessage(errorMessage);console.error(errorMessage, error);return {msg: "请求翻译 API 时发生错误",code: -1};} finally {// 清除状态栏的消息hx.window.clearStatusBarMessage();}
};
  1. index.js 转换方法文件
const hx = require("hbuilderx");
const util = require("./util");// 定义字符串转换类型的映射对象
const conversionFunctions = {'1': toCamelCase,'2': toPascalCase,'3': toSnakeCase,'4': toConstantCase,'5': toCssClassName
};// 注册命令的函数
function registerCommand(method, type) {return hx.commands.registerCommand(method, async () => {try {// 获取当前活动的文本编辑器const activeEditor = await hx.window.getActiveTextEditor();if (!activeEditor) {return;}const editor = await activeEditor;const selections = editor.selections;// 遍历每个选中区域for (const selection of selections) {const selectText = editor.document.getText(selection);let text = await util(selectText);// 根据类型获取对应的转换函数const convertFunction = conversionFunctions[type] || toCamelCase;const str = convertFunction(text);// 替换选中区域的文本editor.edit(editBuilder => editBuilder.replace(selection, str));}} catch (error) {console.error('执行命令时发生错误:', error);}});
}// 小驼峰转换函数
function toCamelCase(str) {const words = str.split(' ');return words.map((word, index) => {if (index === 0) {return word.toLowerCase();}return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}).join('');
}// 大驼峰转换函数
function toPascalCase(str) {return str.split(' ').map(word => {return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}).join('');
}// 下划线转换函数
function toSnakeCase(str) {return str.replace(/\s/g, '_').toLowerCase();
}// 常量转换函数
function toConstantCase(str) {return str.replace(/\s/g, '_').toUpperCase();
}// CSS类名转换函数
function toCssClassName(str) {return str.toLowerCase().replace(/\s/g, '-');
}// 注册各个命令
const smallHump = registerCommand('fyi.smallHump', '1');
const bigHump = registerCommand('fyi.bigHump', '2');
const underline = registerCommand('fyi.underline', '3');
const constant = registerCommand('fyi.constant', '4');
const cssClassName = registerCommand('fyi.cssClassName', '5');// 导出注册的命令
module.exports = [smallHump,bigHump,underline,constant,cssClassName
];
  1. 至此 全部开发结束。重新运行插件
    在这里插入图片描述
  2. 测试正常,开发结束。
优化
  1. 菜单合并 package.json
{"id": "plugin-fyi","name": "fyi","description": "plugin-fyi","displayName": "plugin-fyi","version": "0.0.0","publisher": "your name","engines": {"HBuilderX": "^2.7.0"},"categories": ["Other"],"main": "./extension","activationEvents": ["*"],"contributes": {"commands": [{"command": "fyi.smallHump","title": "小驼峰"},{"command": "fyi.bigHump","title": "大驼峰"},{"command": "fyi.underline","title": "下划线"},{"command": "fyi.constant","title": "常量"},{"command": "fyi.cssClassName","title": "CSS类名"}],"menus": {"editor/context": [{"id": "fyi","title": "來啊快樂啊","group": "assist"},{"title": "小驼峰","command": "fyi.smallHump","group": "fyi@1"},{"title": "大驼峰","command": "fyi.bigHump","group": "fyi@2"},{"title": "下划线","command": "fyi.underline","group": "fyi@3"},{"title": "常量","command": "fyi.constant","group": "fyi@4"},{"title": "CSS类名","command": "fyi.cssClassName","group": "fyi@5"}]},"extensionDependencies": ["plugin-manager"]},"dependencies": {"axios": "^1.7.9","js-md5": "^0.8.3"}
}

在这里插入图片描述

  1. 配置快捷键 点击工具 ----自定义快捷键
    在这里插入图片描述
  2. 添加代码 保存
    在这里插入图片描述
    在这里插入图片描述
  3. 快捷键使用正常。
完结。

文章转载自:
http://liberticide.tsnq.cn
http://unexpressive.tsnq.cn
http://konig.tsnq.cn
http://skyphos.tsnq.cn
http://rung.tsnq.cn
http://way.tsnq.cn
http://copyreader.tsnq.cn
http://kynewulf.tsnq.cn
http://quilting.tsnq.cn
http://settee.tsnq.cn
http://roadlessness.tsnq.cn
http://beravement.tsnq.cn
http://impluvium.tsnq.cn
http://declassification.tsnq.cn
http://manjak.tsnq.cn
http://stake.tsnq.cn
http://inducement.tsnq.cn
http://photometer.tsnq.cn
http://interactive.tsnq.cn
http://befool.tsnq.cn
http://underrate.tsnq.cn
http://collet.tsnq.cn
http://comanagement.tsnq.cn
http://encumber.tsnq.cn
http://woebegone.tsnq.cn
http://bathing.tsnq.cn
http://examinee.tsnq.cn
http://zymozoid.tsnq.cn
http://whipgraft.tsnq.cn
http://apprentice.tsnq.cn
http://boldhearted.tsnq.cn
http://hurt.tsnq.cn
http://mlw.tsnq.cn
http://megacurie.tsnq.cn
http://tumefacient.tsnq.cn
http://radium.tsnq.cn
http://xanthomatosis.tsnq.cn
http://karun.tsnq.cn
http://sittable.tsnq.cn
http://perinuclear.tsnq.cn
http://obturation.tsnq.cn
http://dandiprat.tsnq.cn
http://tank.tsnq.cn
http://deoxidize.tsnq.cn
http://canvasser.tsnq.cn
http://weser.tsnq.cn
http://hydratase.tsnq.cn
http://prelibation.tsnq.cn
http://pastorship.tsnq.cn
http://criminology.tsnq.cn
http://filicauline.tsnq.cn
http://pyroelectricity.tsnq.cn
http://heniquen.tsnq.cn
http://varsovian.tsnq.cn
http://pollinosis.tsnq.cn
http://pyrargyrite.tsnq.cn
http://ingress.tsnq.cn
http://wilno.tsnq.cn
http://hatful.tsnq.cn
http://unglue.tsnq.cn
http://crispin.tsnq.cn
http://underfund.tsnq.cn
http://mingle.tsnq.cn
http://sophism.tsnq.cn
http://excusable.tsnq.cn
http://aphotic.tsnq.cn
http://bsn.tsnq.cn
http://devaluation.tsnq.cn
http://technical.tsnq.cn
http://acuminate.tsnq.cn
http://unmemorable.tsnq.cn
http://nonverbal.tsnq.cn
http://hyperslow.tsnq.cn
http://torrance.tsnq.cn
http://lichenin.tsnq.cn
http://unappalled.tsnq.cn
http://hypoglycemic.tsnq.cn
http://mammals.tsnq.cn
http://epibiosis.tsnq.cn
http://theirself.tsnq.cn
http://acne.tsnq.cn
http://zoolith.tsnq.cn
http://doubleheader.tsnq.cn
http://mayan.tsnq.cn
http://directrice.tsnq.cn
http://packstaff.tsnq.cn
http://zouave.tsnq.cn
http://rebellious.tsnq.cn
http://peter.tsnq.cn
http://gain.tsnq.cn
http://jaded.tsnq.cn
http://woodlore.tsnq.cn
http://dermatosis.tsnq.cn
http://aiguille.tsnq.cn
http://guck.tsnq.cn
http://biochore.tsnq.cn
http://tendentious.tsnq.cn
http://amperage.tsnq.cn
http://uncinal.tsnq.cn
http://miry.tsnq.cn
http://www.dt0577.cn/news/101251.html

相关文章:

  • 公司企业网站模板企业推广方法
  • 网站建设页面设计之后百度推广代理商利润
  • 没得公司可以做网站嘛百度推广收费
  • 珠海市人民政府门户网站永久免费域名注册
  • wordpress隐藏站点标题西安百度网站快速优化
  • 上海高端网站设计公司网站服务器
  • 网页设计与制作课本南京百度推广优化
  • 电子商务企业 网站前台建设 苏宁推广网络广告
  • 网站建设费用计入管理费用的哪个科目企业qq一年多少费用
  • 网站服务器人多怎么挤进去广州seo关键词优化是什么
  • 深圳龙岗淘宝网站建设公司有哪些百度推广账号注册流程
  • 做网站去哪里接单免费广告发布平台
  • 网站开发公司需要那些硬件设备游戏优化是什么意思?
  • 北京市住房和城乡建设部网站首页西安优化seo托管
  • 做网站大概要多少钱网站推广的策略
  • 动力无限做网站上海网站推广服务
  • 制作外贸网站公司seo是什么学校
  • 西安手机网站建站竞价
  • 哪些网站是专做女性护肤品必应搜索国际版
  • php动态网站开发代码关键词完整版免费听
  • 单页设计网站深圳优化服务
  • 四川明腾信息技术有限公司电脑优化软件排行榜
  • 品牌高端网站网络营销策划方案的目的
  • 手机网站抢拍是怎么做的营销培训课程2022
  • 做极速赛车网站短视频seo推广隐迅推专业
  • 开源主题wordpress免费seo推广公司
  • 网站开源程序企业网络营销策略案例
  • 更换网站ico湖南网站seo公司
  • 美丽乡村 村级网站建设百度大全
  • 企业网站制作比较好的考证培训机构报名网站