【sgCreateCallAPIFunctionParam】自定义小工具:敏捷开发→调用接口方法参数生成工具

html 复制代码
<template>
  <div :class="$options.name" class="sgDevTool">
    <sgHead />
    <div class="sg-container">
      <div class="sg-start">
        <div style="margin-bottom: 10px">
          参数列表[逗号模式]
          <el-tooltip
            :content="`如何获取参数列表[逗号模式]?`"
            :effect="`dark`"
            :enterable="false"
            :placement="`top`"
            :transition="`none`"
          >
            <el-link
              icon="el-icon-info"
              :underline="false"
              @click="$refs.image.showViewer = true"
            />
          </el-tooltip>

          <el-image
            ref="image"
            style="display: none"
            :preview-src-list="[`~@/../static/img/${$options.name}.gif`]"
          />
        </div>

        <el-input
          style="margin-bottom: 10px"
          ref="textareaValue1"
          type="textarea"
          :placeholder="`请粘贴apifox.com网站对应接口-运行-body-[x-www-form-urlencoded]-批量编辑-逗号模式,复制内容`"
          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: "sgCreateCallAPIFunctionParam",
  components: {
    sgHead,
    ouputTextarea,
  },
  data() {
    return {
      textareaValue1: localStorage[`sgDevTool/leftTextArea`],
      textareaValue2: "",
    };
  },
  computed: {},

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

        let r = [];
        texts.forEach((v) => {
          if (v.includes("true,")) {
            r.push(
              v
                .split("true,")[1]
                .split(",")[0]
                .replace(/\[/g, ``)
                .replace(/\]/g, ``)
                .replace(/\s+/g, "")
            );
          }
        });

        let params1 = r.join(",");
        let params2 = r.join(",\n");
        this.textareaValue2 = `${params1}

${params2},
`;

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

<style lang="scss" scoped>
@import "~@/css/sgDevTool";
</style>
相关推荐
前端小白从0开始2 分钟前
Vue3项目实现WPS文件预览和内容回填功能
前端·javascript·vue.js·html5·wps·文档回填·文档在线预览
JohnYan21 分钟前
Bun技术评估 - 03 HTTP Server
javascript·后端·bun
开开心心就好1 小时前
高效Excel合并拆分软件
开发语言·javascript·c#·ocr·排序算法·excel·最小二乘法
難釋懷1 小时前
Vue解决开发环境 Ajax 跨域问题
前端·vue.js·ajax
特立独行的猫a1 小时前
Nuxt.js 中的路由配置详解
开发语言·前端·javascript·路由·nuxt·nuxtjs
中微子1 小时前
小白也能懂:JavaScript 原型链和隐藏类的奇妙世界
javascript
咸虾米1 小时前
在uniCloud云对象中定义dbJQL的便捷方法
前端·javascript
梨子同志1 小时前
JavaScript Proxy 和 Reflect
前端·javascript
海的诗篇_1 小时前
移除元素-JavaScript【算法学习day.04】
javascript·学习·算法
汤圆炒橘子1 小时前
状态策略模式的优势分析
前端