Skip to content

Commit

Permalink
fix: 共享到商店侧栏接口、交互调整 && 公共流程支持创建周期任务 && 周期任务添加最低任务间隔时间配置 (#7651)
Browse files Browse the repository at this point in the history
* fix: 共享到商店侧栏 删除【场景标识】 字段 --story=121000017

* fix: 共享到商店侧栏接口、交互调整 --story=121000017

* fix: 公共流程支持创建周期任务 --story=121334648

* fix: 周期任务添加最低任务间隔时间配置 --bug=120737215
# Reviewed, transaction id: 27583

* fix: 字段错误调整 --story=121000017
# Reviewed, transaction id: 27595
  • Loading branch information
ywywZhou authored Dec 24, 2024
1 parent 0b5280a commit 2ce044b
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 44 deletions.
1 change: 1 addition & 0 deletions frontend/desktop/src/assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
var ENABLE_TEMPLATE_MARKET = {{ENABLE_TEMPLATE_MARKET}}
var TEMPLATE_MARKET_HOST = '{{TEMPLATE_MARKET_HOST}}'
var TEMPLATE_MARKET_DOC_URL = '{{TEMPLATE_MARKET_DOC_URL}}'
var PERIODIC_TASK_SHORTEST_TIME = {{PERIODIC_TASK_SHORTEST_TIME}}
// 是否开启通知中心
var ENABLE_NOTICE_CENTER = {{ENABLE_NOTICE_CENTER}}
function getCookie(name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<!-- corn 规则 tips -->
<div id="periodic-cron-tips-html">
<img style="width:542px;height: 258px;" class="ui-img" :src="periodicCronImg">
<p v-if="shortestTime" class="shortest-time-tips">
{{ $t('当前环境配置周期任务间隔不低于 n 分钟,如有特殊需求请联系管理员配置', { n: shortestTime }) }}
</p>
</div>
<div class="time-input">
<input
Expand Down Expand Up @@ -102,7 +105,8 @@
theme: 'light',
content: '#periodic-cron-tips-html',
placement: 'top-start'
}
},
shortestTime: window.PERIODIC_TASK_SHORTEST_TIME
}
},
watch: {
Expand Down Expand Up @@ -350,5 +354,9 @@
.tippy-tooltip {
padding: initial;
}
.shortest-time-tips {
padding: 10px 5px;
color: #ff9c01;
}
}
</style>
6 changes: 5 additions & 1 deletion frontend/desktop/src/config/i18n/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,11 @@ const cn = {
'申明该场景的运维操作风险级别,以便场景使用者决策场景的使用方式': '申明该场景的运维操作风险级别,以便场景使用者决策场景的使用方式',
'请输入标签,enter保存': '请输入标签,enter保存',
'将清空输入信息': '将清空输入信息',
'【n】标签已存在': '【{n}】标签已存在'
'【n】标签已存在': '【{n}】标签已存在',
'场景名称重复:': '场景名称重复:',
'场景名称长度最小3个字符': '场景名称长度最小3个字符',
'请输入群 ID,多个 ID 以分号隔开': '请输入群 ID,多个 ID 以分号隔开',
'当前环境配置周期任务间隔不低于 n 分钟,如有特殊需求请联系管理员配置': '当前环境配置周期任务间隔不低于 {n} 分钟,如有特殊需求请联系管理员配置'
}

export default cn
6 changes: 5 additions & 1 deletion frontend/desktop/src/config/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,11 @@ const en = {
'申明该场景的运维操作风险级别,以便场景使用者决策场景的使用方式': 'Declare the operational risk level of the scene to aid users in deciding how to use the scene',
'请输入标签,enter保存': 'Please enter a tag and press Enter to save',
'将清空输入信息': 'This will clear the input information',
'【n】标签已存在': 'The tag [{n}] already exists'
'【n】标签已存在': 'The tag [{n}] already exists',
'场景名称重复:': 'Duplicate scene name:',
'场景名称长度最小3个字符': 'The scene name must be at least 3 characters long',
'请输入群 ID,多个 ID 以分号隔开': 'Please enter group IDs, separated by semicolons if there are multiple IDs',
'当前环境配置周期任务间隔不低于 n 分钟,如有特殊需求请联系管理员配置': 'In the current environment, the interval for scheduled tasks is no less than {n} minutes. If you have special requirements, please contact the administrator for configuration'
}

export default en
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@
ref="basicConfigForm"
:rules="rules"
:model="formData">
<bk-form-item :label="$t('项目流程')" :required="true" property="flow" data-test-id="periodicEdit_form_selectTemplate">
<bk-form-item :label="$t('流程')" :required="true" property="flow" class="flow-form-item" data-test-id="periodicEdit_form_selectTemplate">
<bk-select
v-model="formData.template_source"
:disabled="isEdit"
:clearable="false"
class="flow-type-select"
@selected="onFlowTypeChange">
<bk-option id="project" :name="$t('项目流程')"></bk-option>
<bk-option id="common" :name="$t('公共流程')"></bk-option>
</bk-select>
<div v-if="isEdit" class="select-box">
<div class="select-wrapper">
<p>
Expand Down Expand Up @@ -87,13 +96,13 @@
<bk-option
v-for="option in templateList"
:key="option.id"
:disabled="!hasPermission(['flow_view'], option.auth_actions)"
:disabled="!hasPermission([flowPermission.view], option.auth_actions)"
:id="option.id"
:name="option.name">
<p
:title="option.name"
v-cursor="{ active: !hasPermission(['flow_view'], option.auth_actions) }"
@click="onTempSelect(['flow_view'], option)">
v-cursor="{ active: !hasPermission([flowPermission.view], option.auth_actions) }"
@click="onTempSelect([flowPermission.view], option)">
{{ option.name }}
</p>
</bk-option>
Expand Down Expand Up @@ -265,6 +274,7 @@
name = '',
is_latest = '',
task_template_name = '',
template_source = 'project',
template_id = '',
template_scheme_ids = []
} = this.curRow
Expand All @@ -273,6 +283,7 @@
formData: {
name,
is_latest: this.isEdit ? is_latest : true,
template_source,
task_template_name,
template_id,
schemeId: this.isEdit && schemeId.length ? schemeId : []
Expand Down Expand Up @@ -366,7 +377,13 @@
return Object.keys(this.periodicConstants).length === 0
},
isCommon () {
return this.curRow.template_source === 'common'
return this.formData.template_source === 'common'
},
flowPermission () {
return {
view: this.isCommon ? 'common_flow_view' : 'flow_view',
create: this.isCommon ? 'common_flow_create_periodic_task' : 'flow_create_periodic_task'
}
},
sideSliderTitle () {
return this.isEdit ? i18n.t('编辑周期任务') : i18n.t('新建周期任务')
Expand Down Expand Up @@ -396,7 +413,10 @@
},
hasNoCreatePerm () {
const { id, auth_actions } = this.templateData
return this.isEdit || !id ? false : !this.hasPermission(['flow_create_periodic_task'], auth_actions)
if (this.isEdit || !id) {
return false
}
return !auth_actions.includes(this.flowPermission.create)
},
schemeSelectPlaceholder () {
return this.formData.template_id && !this.schemeList.length ? i18n.t('此流程无执行方案,无需选择') : i18n.t('请选择')
Expand Down Expand Up @@ -448,7 +468,8 @@
project__id: this.project_id,
limit: 15,
offset,
pipeline_template__name__icontains: this.flowName || undefined
pipeline_template__name__icontains: this.flowName || undefined,
common: this.isCommon
}
const templateListData = await this.loadTemplateList(params)
if (add) {
Expand Down Expand Up @@ -499,7 +520,14 @@
onClearTemplate () {
this.formData.schemeId = []
this.schemeList = []
this.constants = {}
this.periodicConstants = {}
},
onFlowTypeChange () {
this.templateLoading = true
this.formData.template_id = ''
this.formData.name = ''
this.onClearTemplate()
this.handleTplSearch()
},
async getTemplateDate (id) {
// 获取模板详情
Expand Down Expand Up @@ -560,10 +588,9 @@
this.schemeLoading = true
try {
const defaultScheme = await this.loadDefaultSchemeList()
const common = this.curRow.template_source === 'common'
const data = {
isCommon: common || undefined,
project_id: common ? undefined : this.project_id,
isCommon: this.isCommon || undefined,
project_id: this.isCommon ? undefined : this.project_id,
template_id: this.formData.template_id
}
const resp = await this.loadTaskScheme(data)
Expand Down Expand Up @@ -594,11 +621,10 @@
// 获取默认方案列表
async loadDefaultSchemeList () {
try {
const common = this.curRow.template_source === 'common'
const resp = await this.getDefaultTaskScheme({
project_id: this.project_id,
project_id: this.isCommon ? undefined : this.project_id,
template_id: this.formData.template_id,
template_type: common ? 'common' : undefined
template_type: this.isCommon ? 'common' : undefined
})
if (resp.data.length) {
const { scheme_ids: schemeIds } = resp.data[0]
Expand Down Expand Up @@ -762,13 +788,13 @@
if (this.hasNoCreatePerm) {
const { id, name, auth_actions } = this.templateData
const resourceData = {
flow: [{ id, name }],
[this.isCommon ? 'common_flow' : 'flow']: [{ id, name }],
project: [{
id: this.project_id,
name: this.projectName
}]
}
this.applyForPermission(['flow_create_periodic_task'], auth_actions, resourceData)
this.applyForPermission([this.flowPermission.create], auth_actions, resourceData)
return
}
const isCronError = this.$refs.cronRuleSelect.isError
Expand Down Expand Up @@ -865,7 +891,8 @@
cron: cron,
templateId: this.formData.template_id,
schemeIds,
execData: JSON.stringify(pipelineData)
execData: JSON.stringify(pipelineData),
templateSource: this.isCommon ? 'common' : undefined
}
try {
const response = await this.createPeriodic(data)
Expand Down Expand Up @@ -958,6 +985,17 @@
.bk-form-content {
width: 598px;
}
.flow-form-item .bk-form-content {
display: flex;
.bk-select,
.select-box {
flex: 1;
}
.flow-type-select {
flex: 0 0 150px;
margin-right: 15px;
}
}
.scheme-form-item {
.tooltips-icon {
right: 132px !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@
</bk-button>
</div>
</bk-form-item>
<bk-form-item :label="$t('场景名称')" property="name" :required="true" :rules="rules.required">
<bk-form-item :label="$t('场景名称')" property="name" :required="true" :rules="rules.name">
<bk-input
v-if="formData.type === 'create'"
:placeholder="$t('请输入场景名称')"
v-model="formData.name">
minlength="2"
maxlength="50"
show-word-limit
v-model="formData.name"
@focus="repeatSceneInfo = {}">
</bk-input>
<bk-select
v-else
Expand All @@ -56,13 +60,13 @@
:name="option.name">
</bk-option>
</bk-select>
</bk-form-item>
<bk-form-item :label="$t('场景标识')" property="code" :required="true" :rules="rules.required">
<bk-input
v-model="formData.code"
:placeholder="$t('请输入场景标识')"
:disabled="formData.type === 'update'">
</bk-input>
<p v-if="repeatSceneInfo.scene_id" class="scene-repeat-tips">
<span>{{ $t('场景名称重复:') }}</span>
<a target="_blank" :href="repeatSceneInfo.url">
{{ repeatSceneInfo.scene_name }}
<i class="common-icon-jump-link"></i>
</a>
</p>
</bk-form-item>
<bk-form-item :label="$t('场景分类')" property="category" :required="true" :rules="rules.required">
<bk-select
Expand Down Expand Up @@ -114,10 +118,7 @@
</bk-radio-group>
</bk-form-item>
<bk-form-item :label="$t('使用说明')">
<MarkdownEditor
:code="formData.code"
v-model="formData.usage_content.content">
</MarkdownEditor>
<MarkdownEditor v-model="formData.usage_content.content"></MarkdownEditor>
</bk-form-item>
</bk-form>
</template>
Expand Down Expand Up @@ -154,7 +155,6 @@
id: undefined,
type: 'create',
name: '',
code: '',
category: '',
labels: [],
risk_level: '',
Expand All @@ -164,6 +164,15 @@
formData: tools.deepClone(formData),
defaultFormData: tools.deepClone(formData),
rules: {
name: [{
required: true,
message: i18n.t('必填项'),
trigger: 'blur'
}, {
min: 3,
message: i18n.t('场景名称长度最小3个字符'),
trigger: 'blur'
}],
required: [{
required: true,
message: i18n.t('必填项'),
Expand All @@ -176,7 +185,8 @@
categoryList: [],
tagList: [],
riskLevelList: [],
saveLoading: false
saveLoading: false,
repeatSceneInfo: {}
}
},
computed: {
Expand Down Expand Up @@ -323,9 +333,13 @@
const existTplIds = params.templates.map(item => item.id)
selectedTplIds.push(...existTplIds)
}
params.template_ids = [...new Set(selectedTplIds)]
params.templates = [...new Set(selectedTplIds)]
await this.sharedTemplateRecord(params)
const resp = await this.sharedTemplateRecord(params)
if (!resp.result) {
this.repeatSceneInfo = resp.data
return
}
this.showSuccessMessage()
this.$emit('close')
} catch (error) {
Expand Down Expand Up @@ -422,6 +436,22 @@
border-color: #dcdee5;
}
}
.scene-repeat-tips {
display: flex;
align-items: center;
line-height: 16px;
margin-top: 3px;
font-size: 12px;
span {
color: #ff5656;
}
a {
color: #3a84ff;
.common-icon-jump-link {
font-size: 14px;
}
}
}
.category-select::before {
position: absolute;
content: attr(data-placeholder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
event: 'change'
},
props: {
code: {
type: String,
default: ''
},
value: {
type: String,
default: ''
Expand Down Expand Up @@ -75,7 +71,6 @@
// 这里补充上传图片逻辑并将url通过cb传回
const resp = await this.getFileUploadAddr({
file_name: blob.name,
scene_code: this.code || 'flow_template',
scene_type: this.sceneType
})
await axios({
Expand Down
4 changes: 2 additions & 2 deletions frontend/desktop/src/store/modules/templateMarket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const templateMarket = {
return axios.get('/template_market/api/templates_scene/get_file_upload_addr/', { params }).then(response => response.data.data)
},
createLabel ({ commit }, params) {
return axios.post('/template_market/api/templates_scene/create_scene_label/', params).then(response => response.data)
return axios.post('/template_market/api/templates_scene/add_scene_label/', params).then(response => response.data)
},
loadSharedTemplateRecord ({ commit }) {
return axios.get('/template_market/api/templates_scene/').then(response => response.data)
return axios.get('/template_market/api/templates_scene/get_scene_template_list/').then(response => response.data)
},
sharedTemplateRecord ({ commit }, params) {
const { id } = params
Expand Down

0 comments on commit 2ce044b

Please sign in to comment.