-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:文件类型变量上传的文件支持版本管理 #11467 #11482
Changes from all commits
ca9d383
64e3b0f
1f742a1
aca9e7d
9c77be8
d0040e9
8da15d7
2ad42c8
a675734
51913bf
51be166
05c0804
1ddf065
706aa2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,29 +9,36 @@ | |
<vuex-input | ||
class="path-input" | ||
:disabled="disabled" | ||
:handle-change="(name, value) => updatePathFromDirectory(value)" | ||
name="path" | ||
:handle-change="updatePath" | ||
name="directory" | ||
v-validate="{ required: required }" | ||
:data-vv-scope="'pipelineParam'" | ||
:click-unfold="true" | ||
:placeholder="$t('editPage.filePathTips')" | ||
:value="fileDefaultVal.directory" | ||
:value="directory" | ||
:class="{ | ||
'is-diff-param': isDiffParam | ||
}" | ||
/> | ||
<span | ||
v-if="enableVersionControl" | ||
:class="['random-generate', randomSubPath ? '' : 'placeholder']" | ||
> | ||
/{{ randomSubPath || $t('editPage.randomlyGenerate') }}/ | ||
</span> | ||
<vuex-input | ||
class="file-name" | ||
:disabled="disabled" | ||
:handle-change="(name, value) => updatePathFromFileName(value)" | ||
:handle-change="updatePath" | ||
name="fileName" | ||
v-validate="{ required: required }" | ||
:data-vv-scope="'pipelineParam'" | ||
:click-unfold="true" | ||
:placeholder="$t('editPage.fileNameTips')" | ||
:value="fileDefaultVal.fileName" | ||
:value="fileName" | ||
:class="{ | ||
'is-diff-param': isDiffParam | ||
'is-diff-param': isDiffParam, | ||
'border-left-none': !enableVersionControl | ||
}" | ||
/> | ||
</div> | ||
|
@@ -50,15 +57,30 @@ | |
<file-upload | ||
name="fileName" | ||
:file-path="value" | ||
@handle-change="(value) => uploadPathFromFileName(value)" | ||
@handle-change="uploadPathFromFileName" | ||
/> | ||
</div> | ||
<div v-if="!flex"> | ||
<bk-checkbox | ||
:value="enableVersionControl" | ||
@change="handleEnableVersionControl" | ||
> | ||
{{ $t('editPage.enableVersionControl') }} | ||
</bk-checkbox> | ||
<i | ||
class="bk-icon icon-info-circle" | ||
style="color: #63656e;" | ||
v-bk-tooltips="{ content: $t('editPage.versionControlTip'), placement: 'bottom-start' }" | ||
></i> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import VuexInput from '@/components/atomFormField/VuexInput' | ||
import FileUpload from '@/components/atomFormField/FileUpload' | ||
import VuexInput from '@/components/atomFormField/VuexInput' | ||
import { randomString } from '@/utils/util' | ||
|
||
export default { | ||
components: { | ||
VuexInput, | ||
|
@@ -93,47 +115,77 @@ | |
flex: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
enableVersionControl: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
randomSubPath: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
data () { | ||
return { | ||
fileDefaultVal: { | ||
directory: '', | ||
fileName: '' | ||
}, | ||
uploadFileName: '' | ||
directory: '', | ||
fileName: '' | ||
} | ||
}, | ||
watch: { | ||
uploadFileName (val) { | ||
this.updatePathFromFileName(val) | ||
}, | ||
value: { | ||
handler () { | ||
this.splitFilePath() | ||
handler: function (newValue) { | ||
const currentValue = newValue.directory ?? newValue | ||
const lastSlashIndex = currentValue?.lastIndexOf('/') | ||
|
||
this.fileName = currentValue.slice(lastSlashIndex + 1) | ||
|
||
if (this.enableVersionControl && this.randomSubPath) { | ||
const randomStringLastIndex = currentValue.lastIndexOf(`/${this.randomSubPath}`) | ||
this.directory = currentValue.slice(0, randomStringLastIndex) | ||
} else { | ||
this.directory = currentValue.slice(0, lastSlashIndex) | ||
} | ||
}, | ||
immediate: true | ||
} | ||
}, | ||
methods: { | ||
splitFilePath () { | ||
const lastSlashIndex = this.value.lastIndexOf('/') | ||
this.fileDefaultVal.directory = this.value.substr(0, lastSlashIndex) | ||
this.fileDefaultVal.fileName = this.value.substr(lastSlashIndex + 1) | ||
}, | ||
updatePathFromDirectory (value) { | ||
this.fileDefaultVal.directory = value | ||
const val = `${this.fileDefaultVal.directory}/${this.fileDefaultVal.fileName}` | ||
this.handleChange(this.name, val) | ||
}, | ||
updatePathFromFileName (value) { | ||
this.fileDefaultVal.fileName = value | ||
const val = `${this.fileDefaultVal.directory}/${this.fileDefaultVal.fileName}` | ||
this.handleChange(this.name, val) | ||
updatePath (name, value, newFile = false) { | ||
this[name] = value | ||
let randomFilePath = this.enableVersionControl ? this.randomSubPath : '' | ||
|
||
if (newFile && this.enableVersionControl) { | ||
randomFilePath = randomString(8) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const path = [ | ||
this.directory, | ||
...(randomFilePath ? [randomFilePath] : []), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里应该是以this.enableVersionControl为判断条件的 |
||
this.fileName | ||
].join('/') | ||
|
||
// 执行页面需要传json给后端去改变latestRandomStringInPath的值 | ||
const finalValue = this.flex && this.enableVersionControl | ||
? { | ||
directory: path, | ||
latestRandomStringInPath: randomFilePath | ||
} | ||
: path | ||
this.handleChange(this.name, finalValue) | ||
|
||
if (!this.flex) { | ||
this.handleChange('randomStringInPath', randomFilePath) | ||
} | ||
}, | ||
uploadPathFromFileName (value) { | ||
if (this.fileDefaultVal.fileName) return | ||
this.uploadFileName = value | ||
if (!this.fileName) { | ||
this.fileName = value | ||
} | ||
this.updatePath('fileName', this.fileName, true) | ||
}, | ||
handleEnableVersionControl (value) { | ||
this.handleChange('enableVersionControl', value) | ||
this.updatePath('enableVersionControl', value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不需要再这么写呀,直接把外层的randomSubPath更新一下就可以 |
||
} | ||
} | ||
} | ||
|
@@ -143,6 +195,9 @@ | |
.file-param { | ||
width: 100%; | ||
} | ||
.display-flex { | ||
display: flex; | ||
} | ||
.flex-column { | ||
display: flex; | ||
.file-upload { | ||
|
@@ -158,15 +213,26 @@ | |
} | ||
} | ||
} | ||
.border-left-none { | ||
border-left: none; | ||
} | ||
.file-input { | ||
width: 100%; | ||
display: flex; | ||
.path-input { | ||
border-radius: 2px 0 0 2px; | ||
} | ||
.random-generate { | ||
font-size: 12px; | ||
color: #737987; | ||
flex-shrink: 0; | ||
padding: 0 10px; | ||
} | ||
.placeholder { | ||
color: #c4c6cc; | ||
} | ||
.file-name { | ||
border-radius: 0 2px 2px 0; | ||
border-left: 0; | ||
} | ||
} | ||
.is-diff-param { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
外层已经有处理数据了这里的value就不会是object了