From d2e48f69f60436660baa176bdb3673eb7b22814f Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Tue, 21 Feb 2023 07:55:06 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=BD=AF=E4=BB=B6=E6=BA=90?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9A=84=E6=96=B0=E5=A2=9E=E3=80=81=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dong Xia --- src/pages/repository/source/index.vue | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/pages/repository/source/index.vue b/src/pages/repository/source/index.vue index 033e8ba..727f71f 100644 --- a/src/pages/repository/source/index.vue +++ b/src/pages/repository/source/index.vue @@ -236,6 +236,117 @@ export default { this.loading = false }) }, + addSource() { + this.editVisible = true + this.operateType = 'add' + this.formData.planName = '' + this.formData.annotation = '' + this.selectPlan.sourceList = [] + this.title = '新增软件源模板' + }, + handleSubmit() { + this.$refs['planForm'].validate(valid => { + if (!valid) { + return + } + if (this.$refs.sourceSetting.fileText.length === 0) { + this.$notification.error({ message: '新增模板的软件源列表为空' }) + return + } + this.$refs['sourceSetting'].handleSet().then(() => { + const params = { + ...this.formData, + sourceList: this.$refs.sourceSetting.fileText + } + this.confirmLoading = true + if (this.operateType === 'add') { + this.addTitle = '新增软件源模板中...' + insertSource(params).then(res => { + if (res.code === 200) { + this.$notification.success({ message: '新增软件源模板成功' }) + // 调用指定软件源获取软件包总数 + this.addTitle = '更新源模板的软件包中...' + getSourcePackageByPlan({ planName: this.formData.planName }).then((res) => { + if (res.code === 200) { + this.$notification.success({ message: '更新源模板的软件包成功' }) + } + }).finally(() => { + this.editVisible = false + this.confirmLoading = false + }) + this.formData.planName = '' + this.formData.annotation = '' + this.getPlanList() + } else { + this.confirmLoading = false + } + }).catch(() => { + this.confirmLoading = false + }) + return + } + params.id = this.planId + this.addTitle = '编辑软件源模板中...' + updateSourcePlan(params).then(res => { + if (res.code === 200) { + this.$notification.success({ message: '编辑软件源模板成功' }) + // 调用指定软件源获取软件包总数 + this.addTitle = '更新源模板的软件包中...' + getSourcePackageByPlan({ planName: this.formData.planName }).then((res) => { + if (res.code === 200) { + this.$notification.success({ message: '更新源模板的软件包成功' }) + } + }).finally(() => { + this.editVisible = false + this.confirmLoading = false + }) + this.formData.planName = '' + this.formData.annotation = '' + this.getPlanList() + } else { + this.confirmLoading = false + } + }).catch(() => { + this.confirmLoading = false + }) + }) + }) + }, + analysisData(data) { + return data.split('\n').map(item => { + let obj = {} + let urlPre = true // 该标记是否循环到http://或ssh://或ftp:// + const reg = /^(http|ssh|ftp):\/\// + item.split(' ').forEach((item, index) => { + if (item) { + if (reg.test(item)) { + obj[this.keyValueMap[1]] = item + urlPre = false + } else { + if (urlPre) { + obj[this.keyValueMap[0]] = obj[this.keyValueMap[0]] ? obj[this.keyValueMap[0]] + ' ' + item : item + } else { + if (!obj[this.keyValueMap[2]]) { + obj[this.keyValueMap[2]] = item + } else { + obj[this.keyValueMap[3]] = obj[this.keyValueMap[3]] ? obj[this.keyValueMap[3]] + ' ' + item : item + } + } + } + } + }) + return obj + }) + }, + editSource(row) { + this.title = '编辑软件源模板' + this.planId = row.id + this.operateType = 'edit' + this.formData.planName = row.planName + this.formData.annotation = row.annotation + this.selectPlan.sourceList = this.analysisData(row.sourceList) + this.editVisible = true + }, } } \ No newline at end of file -- Gitee