| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{$t('compute.text_323')}}</div>
- <div slot="body">
- <a-alert class="mb-3" :message="$t('compute.baremetal_raid_tip')" type="warning" />
- <a-form
- :form="form.fc">
- <a-form-item :label="$t('compute.text_295')" v-bind="formItemLayout">
- <a-row :gutter="8">
- <a-col :span="22">
- <a-cascader :options="disksOptions" v-decorator="decorators.option" :placeholder="$t('compute.text_219')" @change="cascaderChange" />
- </a-col>
- <a-col :span="2">
- <a-tooltip :title="coutTitle">
- <a-input-number :min="mincount" :max="maxcount" v-decorator="decorators.count" :step="step" />
- </a-tooltip>
- </a-col>
- </a-row>
- </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 _ from 'lodash'
- import { sizestr } from '@/utils/utils'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'BaremetalCreateDiskDialog',
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- option: [
- 'option',
- {
- rules: [
- { required: true, message: this.$t('compute.text_324') },
- ],
- },
- ],
- count: [
- 'count',
- {
- initialValue: 0,
- rules: [
- { required: true, message: this.$t('compute.text_324') },
- ],
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 8,
- },
- labelCol: {
- span: 4,
- },
- },
- driverLimiations: {
- Linux: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 1,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- step: 2,
- },
- {
- value: 'raid5',
- label: 'Raid5',
- min: 3,
- step: 1,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- PCIE: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 1,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- step: 2,
- },
- {
- value: 'raid5',
- label: 'Raid5',
- min: 3,
- step: 1,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- MPT2SAS: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 2,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- max: 2,
- step: 2,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- max: 10,
- step: 2,
- },
- ],
- Mpt3SAS: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 2,
- max: 10,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- max: 2,
- step: 2,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- max: 10,
- step: 2,
- },
- ],
- Mpt2SAS: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 2,
- max: 10,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- max: 2,
- step: 2,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- max: 10,
- step: 2,
- },
- ],
- MegaRaid: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 1,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- max: 2,
- step: 2,
- },
- {
- value: 'raid5',
- label: 'Raid5',
- min: 3,
- step: 1,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- HPSARaid: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 1,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- step: 2,
- },
- {
- value: 'raid5',
- label: 'Raid5',
- min: 3,
- step: 1,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- MarvelRaid: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 1,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- step: 2,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- AdaptecRaid: [
- {
- value: 'none',
- label: this.$t('compute.text_325'),
- min: 1,
- step: 1,
- },
- {
- value: 'raid0',
- label: 'Raid0',
- min: 2,
- step: 1,
- },
- {
- value: 'raid1',
- label: 'Raid1',
- min: 2,
- step: 2,
- },
- {
- value: 'raid10',
- label: 'Raid10',
- min: 4,
- step: 2,
- },
- ],
- },
- disksOptions: [],
- maxcount: 0,
- mincount: 0,
- /*
- * this.params.diskData structure:
- * {
- * "MegaRaid": {
- * "adapter0": [
- * {
- * "count": 4,
- * "end_index": 3,
- * "size": 3814912,
- * "start_index": 0,
- * "type": "HDD"
- * }
- * ]
- * }
- * }
- */
- diskData: JSON.parse(JSON.stringify(this.params.diskData)), // 拷贝参数
- raidTypes: [...Object.keys(this.params.diskData)],
- step: 1,
- startIndex: 0,
- endIndex: 0,
- }
- },
- computed: {
- coutTitle () {
- return this.$t('compute.text_326', [this.mincount, this.maxcount])
- },
- },
- created () {
- this.handleDiskDate()
- },
- methods: {
- // 组装联动数据
- handleDiskDate () {
- this.raidTypes.map(raidType => {
- const raidAdapter = this.diskData[raidType]
- this.params.diskOptionsDate.forEach(item => {
- const adapterKey = item.diskInfo[1]
- raidAdapter[adapterKey].forEach(disks => {
- if (disks.type === item.type && sizestr(disks.size, 'M', 1024) === item.unitSize) {
- disks.count = disks.count - item.count
- disks.start_index = disks.start_index + item.count
- }
- })
- })
- Object.keys(raidAdapter).forEach((key) => {
- const option = {}
- option.value = raidType + ':' + key
- option.label = raidType + ':' + key
- option.children = []
- raidAdapter[key].forEach((item) => {
- let optionL2 = {}
- optionL2 = {
- ...item,
- label: item.type + ':' + sizestr(item.size, 'M', 1024),
- value: item.type + ':' + sizestr(item.size, 'M', 1024),
- start_index: item.start_index,
- end_index: item.end_index,
- children: this._getRaidOptions(raidType, item.count),
- }
- if (optionL2.children.length === 0) return
- option.children.push(optionL2)
- })
- if (option.children.length === 0) return
- // 合并同类型
- const keys = []
- option.children.forEach(item => {
- if (!keys.includes(item.value)) {
- keys.push(item.value)
- }
- })
- const children = []
- keys.forEach(key => {
- const target = option.children.filter(item => item.value === key)
- if (target.length === 1) {
- children.push(target[0])
- } else if (target.length > 1) {
- const count = target.reduce((acc, item) => acc + item.count, 0)
- const item = {
- ...target[0],
- count,
- start_index: target[0].start_index,
- end_index: target.reduce((acc, item) => acc + item.end_index, 0) + target.length,
- children: this._getRaidOptions(raidType, count),
- }
- children.push(item)
- }
- })
- option.children = children
- this.disksOptions.push(option)
- })
- })
- },
- // 计算器
- _getRaidOptions (dirver, diskNum) {
- const options = []
- const limits = this.driverLimiations[dirver]
- if (!limits) {
- return options
- }
- _.forEach(limits, function (item, k) {
- if (diskNum >= item.min) {
- const option = { value: item.value, label: item.label, props: { step: item.step || 1, min: item.min || 1 } }
- if (item.max && item.max <= diskNum) {
- option.props.max = item.max
- } else {
- option.props.max = diskNum - (diskNum - option.props.min) % option.props.step
- }
- options.push(option)
- }
- })
- return options
- },
- // 监听联动改变回调
- cascaderChange (value, selectedOptions) {
- if (selectedOptions) {
- // e.g. 'MegaRaid:adapter0'
- // const adapterOpt = selectedOptions[0]
- // e.g. 'HDD:3.6T'
- const diskOpt = selectedOptions[1]
- // e.g. 'Raid0'
- const raidOpt = selectedOptions[2]
- this.maxcount = raidOpt.props.max
- this.mincount = raidOpt.props.min
- this.step = raidOpt.props.step
- this.startIndex = diskOpt.start_index
- this.endIndex = diskOpt.end_index
- }
- },
- validateForm () {
- return new Promise((resolve, reject) => {
- this.form.fc.validateFields((err, values) => {
- if (!err) {
- resolve(values)
- } else {
- reject(err)
- }
- })
- })
- },
- async handleConfirm () {
- const values = await this.validateForm()
- values.computeCount = values.count
- values.start_index = this.startIndex
- values.end_index = this.endIndex
- this.params.updateData(values)
- this.cancelDialog()
- },
- },
- }
- </script>
|