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