EnableAutoCache.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('aice.mounted_apps')" :count="params.data.length" :action="action" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('aice.mounted_apps.auto_cache.enable')">
  9. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.auto_cache" />
  10. </a-form-item>
  11. </a-form>
  12. </div>
  13. <div slot="footer">
  14. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  15. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  16. </div>
  17. </base-dialog>
  18. </template>
  19. <script>
  20. import DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'InstantAppAutoCacheDialog',
  24. mixins: [DialogMixin, WindowsMixin],
  25. data () {
  26. const isAllClose = this.params.data.every((item) => { return !item.auto_cache })
  27. return {
  28. loading: false,
  29. action: this.$t('aice.mounted_apps.auto_cache.enable'),
  30. form: {
  31. fc: this.$form.createForm(this),
  32. },
  33. decorators: {
  34. auto_cache: [
  35. 'auto_cache',
  36. {
  37. initialValue: !isAllClose,
  38. valuePropName: 'checked',
  39. },
  40. ],
  41. },
  42. formItemLayout: {
  43. wrapperCol: {
  44. span: 19,
  45. },
  46. labelCol: {
  47. span: 5,
  48. },
  49. },
  50. }
  51. },
  52. computed: {
  53. columns () {
  54. const showFields = ['name', 'package', 'version']
  55. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  56. },
  57. },
  58. methods: {
  59. async doSubmit () {
  60. const ids = this.params.data.map(item => item.id)
  61. const values = await this.form.fc.validateFields()
  62. const params = { auto_cache: values.auto_cache }
  63. return this.params.onManager('batchPerformAction', {
  64. id: ids,
  65. managerArgs: {
  66. action: 'enable-auto-cache',
  67. data: params,
  68. },
  69. })
  70. },
  71. async handleConfirm () {
  72. this.loading = true
  73. try {
  74. await this.doSubmit()
  75. this.loading = false
  76. this.cancelDialog()
  77. this.params.refresh()
  78. } catch (error) {
  79. this.loading = false
  80. }
  81. },
  82. },
  83. }
  84. </script>