import-modal.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import { defineComponent, PropType, toRefs } from 'vue'
  18. import { useI18n } from 'vue-i18n'
  19. import Modal from '@/components/modal'
  20. import { useForm } from './use-form'
  21. import { useModal } from './use-modal'
  22. import { NForm, NFormItem, NButton, NUpload, NIcon, NInput } from 'naive-ui'
  23. import { CloudUploadOutlined } from '@vicons/antd'
  24. const props = {
  25. show: {
  26. type: Boolean as PropType<boolean>,
  27. default: false
  28. }
  29. }
  30. export default defineComponent({
  31. name: 'workflowDefinitionImport',
  32. props,
  33. emits: ['update:show', 'update:row', 'updateList'],
  34. setup(props, ctx) {
  35. const { importState } = useForm()
  36. const { handleImportDefinition } = useModal(importState, ctx)
  37. const hideModal = () => {
  38. ctx.emit('update:show')
  39. }
  40. const handleImport = () => {
  41. handleImportDefinition()
  42. }
  43. const customRequest = ({ file }: any) => {
  44. importState.importForm.name = file.name
  45. importState.importForm.file = file.file
  46. }
  47. return {
  48. hideModal,
  49. handleImport,
  50. customRequest,
  51. ...toRefs(importState)
  52. }
  53. },
  54. render() {
  55. const { t } = useI18n()
  56. return (
  57. <Modal
  58. show={this.$props.show}
  59. title={t('project.workflow.upload')}
  60. onCancel={this.hideModal}
  61. onConfirm={this.handleImport}
  62. confirmLoading={this.saving}
  63. >
  64. <NForm
  65. rules={this.importRules}
  66. ref='importFormRef'
  67. >
  68. <NFormItem label={t('project.workflow.upload_file')} path='file'>
  69. <NButton>
  70. <NUpload
  71. v-model={[this.importForm.file, 'value']}
  72. customRequest={this.customRequest}
  73. showFileList={false}
  74. >
  75. <NButton text>
  76. 上传
  77. <NIcon>
  78. <CloudUploadOutlined />
  79. </NIcon>
  80. </NButton>
  81. </NUpload>
  82. </NButton>
  83. </NFormItem>
  84. <NFormItem label={t('project.workflow.file_name')} path='name'>
  85. <NInput
  86. v-model={[this.importForm.name, 'value']}
  87. placeholder={t('project.workflow.enter_name_tips')}
  88. />
  89. </NFormItem>
  90. </NForm>
  91. </Modal>
  92. )
  93. }
  94. })