index.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <Modal
  3. v-model:open="show"
  4. :title="title"
  5. :width="width"
  6. :destroyOnClose="true"
  7. >
  8. <Editor v-model:code="code" v-bind="$attrs"/>
  9. <template #footer>
  10. <slot name="footer">
  11. <Button @click="close">取消</Button>
  12. <Button type="primary" @click="handleOk">确定</Button>
  13. </slot>
  14. </template>
  15. </Modal>
  16. </template>
  17. <script lang="ts">
  18. import { Modal, Button } from "ant-design-vue";
  19. import { ref, defineComponent } from "vue";
  20. import Editor from "./Editor.vue";
  21. export default defineComponent({
  22. name: "DEditorModal",
  23. components: {
  24. Modal,
  25. Editor,
  26. Button
  27. },
  28. props: {
  29. title: {
  30. type: String,
  31. default: "编辑",
  32. },
  33. width: {
  34. type: Number,
  35. default: 800,
  36. },
  37. },
  38. emits: ["ok"],
  39. setup(_, { emit }) {
  40. const show = ref(false);
  41. const code = ref("");
  42. const handleOk = () => {
  43. // TODO: 检验code
  44. emit("ok", code.value);
  45. show.value = false;
  46. };
  47. const open = (codeStr: string) => {
  48. show.value = true;
  49. code.value = codeStr;
  50. };
  51. const close = () => {
  52. show.value = false;
  53. };
  54. return {
  55. open,
  56. close,
  57. code,
  58. handleOk,
  59. show
  60. };
  61. },
  62. });
  63. </script>
  64. <style scoped></style>