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

【sgCreateCallAPIFunction】自定义小工具:敏捷开发→调用接口方法代码生成工具

 

<template>
  <div :class="$options.name" class="sgDevTool">
    
    <sgHead />
    <div class="sg-container">
      <div class="sg-start">
        <div style="margin-bottom: 10px">调用接口方法定义列表</div>

        <el-input
          style="margin-bottom: 10px"
          ref="textareaValue1"
          type="textarea"
          :placeholder="`请粘贴sf.js中定义的调用方法代码片段(含注释内容)`"
          v-model="textareaValue1"
          show-word-limit
        />

        <el-button type="primary" @click="createResult">运行</el-button>
      </div>
      <div class="sg-center">→</div>

      <div class="sg-end">
        <ouputTextarea ref="ouputTextarea" v-model="textareaValue2" />
      </div>
    </div>
  </div>
</template>

<script>
import sgHead from "@/vue/components/sgHead";
import ouputTextarea from "@/vue/components/ouputTextarea";
export default {
  name: "sgCreateCallAPIFunction",
  components: {
    sgHead,
    ouputTextarea,
  },
  data() {
    return {

      textareaValue1: localStorage[`sgDevTool/leftTextArea`],
      textareaValue2: "",
    };
  },
  watch: {
    textareaValue1(newValue, oldValue) {
      newValue && this.createResult(newValue);
      localStorage[`sgDevTool/leftTextArea`] = newValue;
    },
  },
  created() {},
  methods: {
    createResult(d) {
      if (this.textareaValue1.includes("//")) {
        let texts = this.$g.getMultiLineTexts(this.textareaValue1);

        let apis = [];
        texts.forEach((v, i) => {
          if (v.includes(`_this)`)) {
            apis.push({
              label: texts[i - 1],
              functionName: v.split("({")[0],
              params: v
                .split("({")[1]
                .split("}")[0]
                .split(",")
                .map((v) => {
                  v = v.trim();
                  if (v === "cb") {
                    return `cb: (d) => { 
  //回调函数
},`;
                  } else {
                    return v;
                  }
                }),
            });
          }
        });

        let r = apis.map(
          (v) => `${v.label}
this.$f.${v.functionName}({
  ${v.params.join(": ,\n")}
},this);`
        );

        this.textareaValue2 = r.join("\n\n");

        this.$refs.ouputTextarea.copyResult(); //自动复制生成结果
      } else {
        return this.$message.error(this.$refs.textareaValue1.$attrs.placeholder);
      }
    },
    
  },
};
</script>

<style lang="scss" scoped>
@import "~@/css/sgDevTool";
</style>


http://www.kler.cn/news/315640.html

相关文章:

  • Java String trim()方法
  • 如何创建模板提示prompt
  • Linux移植之系统烧写
  • Redis 中 String 字符串类型详解
  • 2024年中国研究生数学建模竞赛B题(华为题目)WLAN组网中网络吞吐量建模一
  • libtorch落地AI项目的一些总结
  • 面试题(八)
  • OpenCV_图像膨胀腐蚀与形态学操作及具体应用详解
  • 分布式安装LNMP
  • [OpenCV] 数字图像处理 C++ 学习——16直方图均衡化、直方图比较 详细讲解+附完整代码
  • 超详细的XML介绍【附带dom4j操作XML】
  • 口腔检测系统源码分享
  • php怎么连接使用kafka
  • 【AI算法岗面试八股面经【超全整理】——NLP】
  • 学生管理系统1.0版本
  • Kotlin 基本介绍(一)
  • 如何确保消息只被消费一次:Java实现详解
  • Python 中的 HTTP 编程入门,如何使用 Requests 请求网络
  • 实现人体模型可点击
  • Kotlin 枚举和 when 表达式(六)
  • 关于Python sklearn CountVectorizer使用详解
  • 多模态论文串讲-学习笔记(上)
  • docker配置镜像加速器
  • 亚马逊IP关联揭秘:发生ip关联如何处理
  • 【BEV 视图变换】Ray-based(2): 代码复现+画图解释 基于深度估计、bev_pool
  • MoveIt控制机械臂的运动实现——机器人抓取系统基础系列(二)
  • 带你0到1之QT编程:十七、Http协议实战,实现一个简单服务器和一个客户端进行http协议通信
  • 校园美食发现:Spring Boot技术的美食社交平台
  • Flyway 版本迁移文件
  • 【Kubernetes】常见面试题汇总(三十二)