wechat_rob_mini/pages/prompt/import.js

41 lines
1.2 KiB
JavaScript

const { request, buildResultView } = require('../../utils/request');
Page({
data: {
content: '',
check_only: 'false',
overwrite: 'false',
task_id: '',
task_name: '',
robot_id: '',
result: '',
resultCards: []
},
onInput(e) {
const key = e.currentTarget.dataset.key;
this.setData({ [key]: e.detail.value });
},
async parse() {
const result = await request({
url: '/api/prompt/import',
method: 'POST',
data: { content: this.data.content, check_only: true }
});
const view = buildResultView(result);
this.setData({ result: view.text, resultCards: view.cards });
},
async confirm() {
const payload = {
content: this.data.content,
check_only: String(this.data.check_only).toLowerCase() === 'true',
overwrite: String(this.data.overwrite).toLowerCase() === 'true',
task_id: this.data.task_id ? Number(this.data.task_id) : undefined,
task_name: this.data.task_name,
robot_id: this.data.robot_id ? Number(this.data.robot_id) : undefined
};
const result = await request({ url: '/api/prompt/import', method: 'POST', data: payload });
const view = buildResultView(result);
this.setData({ result: view.text, resultCards: view.cards });
}
});