OperationModal.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { css } from "@linaria/core";
  2. import { Button, Form, Input } from "ant-design-vue";
  3. import { Rule } from "ant-design-vue/lib/form";
  4. import { queenApi } from "queenjs";
  5. import { defineComponent, reactive, ref } from "vue";
  6. import { object } from "vue-types";
  7. import Thumbnail from "./Thumbnail";
  8. const layout = {
  9. labelCol: { span: 6 },
  10. wrapperCol: { span: 16 },
  11. };
  12. export default defineComponent({
  13. props: {
  14. data: object<IStyle>(),
  15. },
  16. setup(props) {
  17. const modal = queenApi.useDialog();
  18. const formRef = ref();
  19. const formState = reactive({
  20. scenePack: props.data?.scenePack || {},
  21. name: props.data?.name || "",
  22. });
  23. const checkPack = async (_rule: Rule, value: any) => {
  24. if (!value._id) {
  25. return Promise.reject("款式不能为空");
  26. } else {
  27. return Promise.resolve();
  28. }
  29. };
  30. const submit = async () => {
  31. const values = await formRef.value?.validateFields();
  32. values.thumbnail = values.scenePack.thumbnail;
  33. modal.submit(values);
  34. };
  35. return () => {
  36. return (
  37. <div class={modalStyle}>
  38. <Form {...layout} ref={formRef} model={formState}>
  39. <Form.Item
  40. name="scenePack"
  41. label="选择款式"
  42. rules={[{ validator: checkPack, trigger: "change" }]}
  43. >
  44. <Thumbnail v-model={[formState.scenePack, "value"]} />
  45. </Form.Item>
  46. <Form.Item
  47. name="name"
  48. label="款式名"
  49. rules={[{ required: true, message: "款式不能为空" }]}
  50. >
  51. <Input
  52. v-model={[formState.name, "value"]}
  53. placeholder="请输入款式名"
  54. />
  55. </Form.Item>
  56. <Form.Item class="text-center" wrapperCol={{ span: 24 }}>
  57. <Button onClick={() => modal.cancel()}>取消</Button>
  58. <Button type="primary" class="ml-10px" onClick={submit}>
  59. 确定
  60. </Button>
  61. </Form.Item>
  62. </Form>
  63. </div>
  64. );
  65. };
  66. },
  67. });
  68. const modalStyle = css`
  69. .content {
  70. padding-top: 20px;
  71. padding-bottom: 10px;
  72. text-align: left;
  73. }
  74. .footer {
  75. margin-bottom: 0;
  76. text-align: right;
  77. }
  78. `;