|
@@ -1,19 +1,141 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import { reactive } from "vue";
|
|
|
|
-import list from "./modules/list.vue";
|
|
|
|
|
|
+import {onMounted, reactive, ref} from "vue";
|
|
|
|
+import * as $api from "@/api/platform/index";
|
|
|
|
+import {message} from "@/utils/message";
|
|
|
|
+import type {FormInstance} from "element-plus";
|
|
|
|
+import {cloneDeep} from "@pureadmin/utils";
|
|
|
|
|
|
-defineOptions({
|
|
|
|
- name: "platformManage"
|
|
|
|
-});
|
|
|
|
|
|
+defineOptions({name: "templateEdit"});
|
|
|
|
+const isDetail = ref(false);
|
|
|
|
+const formRef = ref<FormInstance>();
|
|
|
|
+// 初始化数据
|
|
|
|
+const initData = {
|
|
|
|
+ serviceId: undefined,
|
|
|
|
+ privateKey: undefined,
|
|
|
|
+ publicKey: undefined,
|
|
|
|
+ status: 1
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 表单校验规则
|
|
|
|
+const formRules = {
|
|
|
|
+ appId: [{required: true, message: "appId不能为空", trigger: "blur"}],
|
|
|
|
+ privateKey: [{required: true, message: "密钥不能为空", trigger: "blur"}],
|
|
|
|
+ publicKey: [{required: true, message: "公钥不能为空", trigger: "blur"}]
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 页面数据
|
|
const pageData: any = reactive({
|
|
const pageData: any = reactive({
|
|
- mode: "table"
|
|
|
|
|
|
+ dialogVisible: false,
|
|
|
|
+ title: "",
|
|
|
|
+ formLoading: false,
|
|
|
|
+ mode: "add",
|
|
|
|
+ isUpdate: false,
|
|
|
|
+ // 表单数据
|
|
|
|
+ formData: initData,
|
|
|
|
+ formRules: formRules
|
|
|
|
+});
|
|
|
|
+// 暴露给父级调用
|
|
|
|
+const emits = defineEmits(["ok", "close"]);
|
|
|
|
+
|
|
|
|
+const _save = () => {
|
|
|
|
+ pageData.formLoading = true;
|
|
|
|
+ const _data = cloneDeep(pageData.formData);
|
|
|
|
+ $api
|
|
|
|
+ .save(_data)
|
|
|
|
+ .then((res: any) => {
|
|
|
|
+ if (res.success) {
|
|
|
|
+ _confirm();
|
|
|
|
+ } else {
|
|
|
|
+ message(res.message, {type: "warning"});
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .finally(() => {
|
|
|
|
+ pageData.formLoading = false;
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+const _update = () => {
|
|
|
|
+ pageData.formLoading = true;
|
|
|
|
+ const _data = cloneDeep(pageData.formData);
|
|
|
|
+ $api
|
|
|
|
+ .update(pageData.formData.id, _data)
|
|
|
|
+ .then((res: any) => {
|
|
|
|
+ if (res.success) {
|
|
|
|
+ _confirm();
|
|
|
|
+ } else {
|
|
|
|
+ message(res.message, {type: "warning"});
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .finally(() => {
|
|
|
|
+ pageData.formLoading = false;
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+const _confirm = () => {
|
|
|
|
+ message("操作成功",{type:"success"});
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 确定并关闭弹窗
|
|
|
|
+const handleConfirm = () => {
|
|
|
|
+ formRef.value!.validate((isValid: boolean) => {
|
|
|
|
+ if (isValid) {
|
|
|
|
+ const {id} = pageData.formData;
|
|
|
|
+ if (id) {
|
|
|
|
+ _update();
|
|
|
|
+ } else {
|
|
|
|
+ _save();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ message("表单校验失败", {type: "warning"});
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+onMounted(() => {
|
|
|
|
+ $api.info().then((res: any) => {
|
|
|
|
+ pageData.formData = res.result;
|
|
|
|
+ console.log(pageData.formData);
|
|
|
|
+ });
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
- <el-card :shadow="'never'">
|
|
|
|
- <template #default>
|
|
|
|
- <list :mode="pageData.mode" />
|
|
|
|
- </template>
|
|
|
|
- </el-card>
|
|
|
|
|
|
+ <el-form
|
|
|
|
+ ref="formRef"
|
|
|
|
+ :model="pageData.formData"
|
|
|
|
+ style="width: 50%; margin: 20px auto 0"
|
|
|
|
+ label-width="auto"
|
|
|
|
+ :rules="pageData.formRules"
|
|
|
|
+ >
|
|
|
|
+ <el-form-item label="appId" prop="appId">
|
|
|
|
+ <el-input
|
|
|
|
+ v-model="pageData.formData.appId"
|
|
|
|
+ clearable
|
|
|
|
+ placeholder="请输入appId"
|
|
|
|
+ size="small"
|
|
|
|
+ :readonly="isDetail"
|
|
|
|
+ />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="密钥" prop="privateKey">
|
|
|
|
+ <el-input
|
|
|
|
+ v-model="pageData.formData.privateKey"
|
|
|
|
+ clearable
|
|
|
|
+ placeholder="请输入密钥"
|
|
|
|
+ size="small"
|
|
|
|
+ :readonly="isDetail"
|
|
|
|
+ />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="公钥" prop="publicKey">
|
|
|
|
+ <el-input
|
|
|
|
+ v-model="pageData.formData.publicKey"
|
|
|
|
+ clearable
|
|
|
|
+ placeholder="请输入公钥"
|
|
|
|
+ size="small"
|
|
|
|
+ :readonly="isDetail"
|
|
|
|
+ />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <div>
|
|
|
|
+ <el-button v-if="!isDetail" type="primary" @click="handleConfirm"
|
|
|
|
+ >保存</el-button
|
|
|
|
+ >
|
|
|
|
+ </div>
|
|
|
|
+ </el-form>
|
|
|
|
+
|
|
</template>
|
|
</template>
|