InstantAppCreate.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <base-dialog :width="900" @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.create') }}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc" v-bind="formItemLayout" hideRequiredMark>
  6. <a-form-item :label="$t('aice.project')">
  7. <domain-project
  8. :fc="form.fc"
  9. :fd="form.fd"
  10. :decorators="{ project: decorators.project, domain: decorators.domain }" />
  11. </a-form-item>
  12. <a-form-item :label="$t('common.name')">
  13. <a-input v-decorator="decorators.name" placeholder="com.ss.android.ugc.aweme-23.0.1" />
  14. <template v-slot:extra>
  15. <name-repeated res="instant_apps" :name="form.fd.name" :default-text="$t('aice.name_repeat_extra')" />
  16. </template>
  17. </a-form-item>
  18. <a-form-item :label="$t('aice.mounted_apps.package')">
  19. <a-input v-decorator="decorators.package" placeholder="com.ss.android.ugc.aweme" />
  20. </a-form-item>
  21. <a-form-item :label="$t('aice.mounted_apps.version')">
  22. <a-input v-decorator="decorators.version" placeholder="23.0.1" />
  23. </a-form-item>
  24. <a-form-item :label="$t('aice.mounted_apps.mounts')">
  25. <a-textarea v-decorator="decorators.mounts" :placeholder="mountsExample" :auto-size="{ minRows: 3, maxRows: 5 }" />
  26. </a-form-item>
  27. <a-form-item :label="$t('aice.template')">
  28. <base-select
  29. v-decorator="decorators.image_id"
  30. resource="images"
  31. :params="templateParams"
  32. filterable
  33. :selectProps="{ placeholder: $t('common.tips.select', [$t('aice.template')]) }" />
  34. </a-form-item>
  35. </a-form>
  36. </div>
  37. <div slot="footer">
  38. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  39. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  40. </div>
  41. </base-dialog>
  42. </template>
  43. <script>
  44. import { mapGetters } from 'vuex'
  45. import DialogMixin from '@/mixins/dialog'
  46. import WindowsMixin from '@/mixins/windows'
  47. import DomainProject from '@/sections/DomainProject'
  48. import NameRepeated from '@/sections/NameRepeated'
  49. import { isRequired } from '@/utils/validate'
  50. export default {
  51. name: 'InstantAppCreateDialog',
  52. components: {
  53. DomainProject,
  54. NameRepeated,
  55. },
  56. mixins: [DialogMixin, WindowsMixin],
  57. data () {
  58. return {
  59. loading: false,
  60. form: {
  61. fc: this.$form.createForm(this, {
  62. onValuesChange: (props, values) => {
  63. Object.keys(values).forEach((key) => {
  64. this.$set(this.form.fd, key, values[key])
  65. })
  66. },
  67. }),
  68. fd: {},
  69. },
  70. decorators: {
  71. domain: [
  72. 'domain',
  73. {
  74. rules: [
  75. { validator: isRequired(), message: this.$t('rules.domain'), trigger: 'change' },
  76. ],
  77. },
  78. ],
  79. project: [
  80. 'project',
  81. {
  82. rules: [
  83. { validator: isRequired(), message: this.$t('rules.project'), trigger: 'change' },
  84. ],
  85. },
  86. ],
  87. name: [
  88. 'name',
  89. {
  90. rules: [
  91. { required: true, message: this.$t('common.tips.input', [this.$t('common.name')]) },
  92. ],
  93. },
  94. ],
  95. package: [
  96. 'package',
  97. {
  98. rules: [
  99. { required: true, message: this.$t('common.tips.input', [this.$t('aice.mounted_apps.package')]) },
  100. ],
  101. },
  102. ],
  103. version: [
  104. 'version',
  105. {
  106. rules: [
  107. { required: true, message: this.$t('common.tips.input', [this.$t('aice.mounted_apps.version')]) },
  108. ],
  109. },
  110. ],
  111. mounts: [
  112. 'mounts',
  113. {
  114. rules: [
  115. { required: true, message: this.$t('common.tips.input', [this.$t('aice.mounted_apps.mounts')]) },
  116. ],
  117. },
  118. ],
  119. image_id: [
  120. 'image_id',
  121. {
  122. rules: [
  123. { required: true, message: this.$t('common.tips.input', [this.$t('aice.template')]) },
  124. ],
  125. },
  126. ],
  127. },
  128. formItemLayout: {
  129. wrapperCol: {
  130. span: 20,
  131. },
  132. labelCol: {
  133. span: 3,
  134. },
  135. },
  136. }
  137. },
  138. computed: {
  139. ...mapGetters(['userInfo']),
  140. mountsExample () {
  141. return '/data/app/~~AiggKR4DW03_Ue4jSG2YmQ==\n/data/data/com.ss.android.ugc.aweme\n/data/media/0/Android/data/com.ss.android.ugc.aweme'
  142. },
  143. templateParams () {
  144. const ret = {
  145. scope: this.scope,
  146. 'disk_formats.0': 'tgz',
  147. details: false,
  148. }
  149. return ret
  150. },
  151. },
  152. methods: {
  153. async handleConfirm () {
  154. try {
  155. const values = await this.form.fc.validateFields()
  156. const manager = new this.$Manager('instant_apps', '')
  157. const mountPaths = values.mounts.split('\n')
  158. const data = {
  159. generate_name: values.name,
  160. package: values.package,
  161. version: values.version,
  162. mounts: mountPaths,
  163. image_id: values.image_id,
  164. project_id: values.project?.key || this.userInfo.projectId,
  165. }
  166. manager.create({
  167. data,
  168. })
  169. } catch (error) {
  170. throw error
  171. } finally {
  172. this.loading = false
  173. }
  174. this.params.callback && this.params.callback()
  175. this.cancelDialog()
  176. this.params.refresh && this.params.refresh()
  177. },
  178. },
  179. }
  180. </script>