| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{$t('k8s.text_68')}}</div>
- <div slot="body">
- <dialog-selected-tips :count="params.data.length" :name="$t('k8s.text_64')" :action="$t('k8s.text_68')" />
- <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
- <a-form
- v-bind="formItemLayout"
- :form="form.fc">
- <a-form-item :label="$t('k8s.text_69')" v-if="!params.hideReplicas">
- <a-input v-decorator="decorators.replicas" :min="0" type="number" :placeholder="$t('k8s.text_70')" :addonAfter="$t('k8s.text_71')" @blur="change" />
- </a-form-item>
- </a-form>
- </div>
- <div slot="footer">
- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import * as R from 'ramda'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- import expectStatus from '@/constants/expectStatus'
- export default {
- name: 'K8SSetLimitDialog',
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- form: {
- fc: this.$form.createForm(this),
- fd: {},
- },
- data: this.params.data[0],
- decorators: {
- replicas: [
- 'replicas',
- {
- rules: [
- { required: true, message: this.$t('k8s.text_70') },
- ],
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 19,
- },
- labelCol: {
- span: 5,
- },
- },
- replicas: 3,
- }
- },
- created () {
- this.fetchData()
- },
- methods: {
- change (e) {
- const val = Number(e.target.value)
- if (R.is(Number, val) && !Number.isNaN(val) && val >= 0) {
- } else {
- this.form.fc.setFieldsValue({
- replicas: this.replicas,
- })
- }
- },
- async fetchData () {
- const { data } = await this.params.onManager('get', {
- managerArgs: {
- id: this.data.id,
- params: {
- cluster: this.data.cluster,
- namespace: this.data.namespace,
- },
- },
- })
- this.replicas = data.replicas || 3
- this.$nextTick(() => {
- this.form.fc.setFieldsValue({
- replicas: this.replicas,
- })
- })
- },
- async doUpdate (params) {
- const data = {
- replicas: params.replicas,
- cluster: this.data.cluster,
- namespace: this.data.namespace,
- }
- if (params.hideReplicas) delete data.replicas
- try {
- await this.params.onManager('update', {
- id: this.data.id,
- managerArgs: {
- data,
- },
- steadyStatus: Object.values(expectStatus.k8s_resource).flat(),
- })
- } catch (error) {
- throw error
- }
- },
- async handleConfirm () {
- this.loading = true
- try {
- const values = await this.form.fc.validateFields()
- await this.doUpdate(values)
- this.loading = false
- this.cancelDialog()
- if (R.is(Function, this.params.success)) this.params.success()
- } catch (error) {
- this.loading = false
- throw error
- }
- },
- },
- }
- </script>
|