addBan.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <component
  3. is="a-modal"
  4. :width="tool.getDevice() === 'mobile' ? '100%' : '600px'"
  5. v-model:visible="visible"
  6. :title="title"
  7. :mask-closable="false"
  8. :ok-loading="loading"
  9. @cancel="close"
  10. @before-ok="submit"
  11. >
  12. <!-- 表单信息 start -->
  13. <a-form
  14. ref="formRef"
  15. :model="formData"
  16. :rules="rules"
  17. :auto-label-width="true"
  18. >
  19. <a-form-item label="操作" field="action">
  20. <a-radio-group v-model="formData.action">
  21. <a-radio value="1">封禁</a-radio>
  22. <a-radio value="2">解除封禁</a-radio>
  23. </a-radio-group>
  24. </a-form-item>
  25. <a-form-item label="类型" field="type">
  26. <a-radio-group v-model="formData.type">
  27. <a-radio value="1">UID</a-radio>
  28. <a-radio value="2">IP</a-radio>
  29. <a-radio value="3">设备</a-radio>
  30. </a-radio-group>
  31. </a-form-item>
  32. <a-form-item label="值" field="value">
  33. <a-textarea v-model="formData.value" placeholder="请输入值" :rows="3">
  34. </a-textarea>
  35. <template #extra> 多个请用英文逗号,隔开 </template>
  36. </a-form-item>
  37. <a-form-item label="理由" field="reason">
  38. <a-textarea v-model="formData.reason" placeholder="请输入理由" />
  39. </a-form-item>
  40. </a-form>
  41. <!-- 表单信息 end -->
  42. </component>
  43. </template>
  44. <script setup>
  45. import { ref, reactive, computed } from "vue";
  46. import tool from "@/utils/tool";
  47. import { Message, Modal } from "@arco-design/web-vue";
  48. import api from "../../api/customer/account";
  49. const emit = defineEmits(["success"]);
  50. // 引用定义
  51. const visible = ref(false);
  52. const loading = ref(false);
  53. const formRef = ref();
  54. let title = computed(() => {
  55. return "封禁|解除封禁";
  56. });
  57. // 表单初始值
  58. const initialFormData = {
  59. action: "",
  60. type: "",
  61. value: "",
  62. reason: "",
  63. };
  64. // 表单信息
  65. const formData = reactive({ ...initialFormData });
  66. // 验证规则
  67. const rules = {
  68. action: [{ required: true, message: "操作必需填写" }],
  69. type: [{ required: true, message: "类型必需填写" }],
  70. value: [{ required: true, message: "值必需填写" }],
  71. reason: [{ required: true, message: "理由必需填写" }],
  72. };
  73. // 打开弹框
  74. const open = async () => {
  75. formRef.value.clearValidate();
  76. formRef.value.resetFields();
  77. visible.value = true;
  78. await initPage();
  79. };
  80. // 初始化页面数据
  81. const initPage = async () => {};
  82. // 数据保存
  83. const submit = async (done) => {
  84. const validate = await formRef.value?.validate();
  85. if (!validate) {
  86. loading.value = true;
  87. let data = { ...formData };
  88. let result = await api.saveBanApi(data);
  89. if (result.code === 200) {
  90. Message.success("操作成功");
  91. emit("success");
  92. done(true);
  93. }
  94. // 防止连续点击提交
  95. setTimeout(() => {
  96. loading.value = false;
  97. }, 500);
  98. }
  99. done(false);
  100. };
  101. // 关闭弹窗
  102. const close = () => (visible.value = false);
  103. defineExpose({ open });
  104. </script>