Forráskód Böngészése

feat: 支持小程序删除团队背景资料

Developer 3 hete
szülő
commit
81600b3a03

+ 5 - 5
components/CusTeamBackgroundFiles/index.vue

@@ -19,7 +19,7 @@
 					</view>
 					<view class="file-actions adfac">
 						<view class="file-action" @click="previewFile(file)">{{ previewingId === file.id ? '打开中' : '查看' }}</view>
-						<view class="file-action danger" @click="removeFile(file)">停用</view>
+						<view class="file-action danger" @click="removeFile(file)">删除</view>
 					</view>
 				</view>
 			</view>
@@ -406,8 +406,8 @@ export default {
 			if (!teamId || file.id === undefined || file.id === null
 				|| !this.isCurrentFile(file, teamId, generation)) return
 			uni.showModal({
-				title: '停用资料',
-				content: `确定停用“${file.fileName || file.name || '该文件'}”吗?`,
+				title: '删除资料',
+				content: `确定删除“${file.fileName || file.name || '该文件'}”吗?`,
 				confirmColor: '#199C9C',
 				success: async result => {
 					if (!result.confirm || !this.isCurrentFile(file, teamId, generation)) return
@@ -415,9 +415,9 @@ export default {
 						await disableTeamBackgroundFile(teamId, file.id)
 						if (!this.isCurrentContext(teamId, generation)) return
 						await this.refreshFiles(teamId)
-						if (!this.componentDestroyed) this.$showToast('已停用')
+						if (!this.componentDestroyed) this.$showToast('已删除')
 					} catch (error) {
-						this.showError(error, '停用失败,请重试')
+						this.showError(error, '删除失败,请重试')
 					}
 				}
 			})

+ 47 - 0
tests/teamBackgroundFile.test.js

@@ -1086,6 +1086,52 @@ async function testFileActionsWaitForCurrentListAndDocumentContext() {
 	assert.ok(toasts.some(message => String(message).includes('open failed')))
 }
 
+async function testUploadedFileUsesDeleteWordingAndRefreshesAfterDelete() {
+	let modalOptions
+	const disableCalls = []
+	const toasts = []
+	const component = await loadVueComponent(backgroundComponentPath, {
+		uni: {
+			showModal(options) {
+				modalOptions = options
+			}
+		},
+		http: {
+			disableTeamBackgroundFile(teamId, fileId) {
+				disableCalls.push([teamId, fileId])
+				return Promise.resolve(true)
+			},
+			listTeamBackgroundFiles() {
+				return Promise.resolve([])
+			}
+		}
+	})
+	const instance = instantiateComponent(component, {
+		teamId: '',
+		editable: true,
+		$showToast(message) { toasts.push(message) },
+		$emit() {}
+	})
+	instance.resetTeamContext(5)
+	const file = { id: 51, fileName: '背景资料.pdf' }
+	instance.files = [file]
+	instance.filesReady = true
+
+	instance.removeFile(file)
+
+	assert.equal(modalOptions.title, '删除资料')
+	assert.match(modalOptions.content, /确定删除/)
+	modalOptions.success({ confirm: true })
+	await flushPromises()
+
+	assert.deepEqual(disableCalls, [[5, 51]])
+	assert.deepEqual(instance.files, [])
+	assert.ok(toasts.includes('已删除'))
+	const source = fs.readFileSync(backgroundComponentPath, 'utf8')
+	assert.match(source, />删除<\/view>/)
+	assert.doesNotMatch(source, /停用资料|已停用|停用失败/)
+}
+
 async function testSameTeamRefreshFailurePreservesExistingFilesAndCount() {
 	const listRequest = createDeferred()
 	const emittedCounts = []
@@ -1563,6 +1609,7 @@ async function main() {
 	await testDeferredPcWaiterSingleFlightFinishesAllCallers()
 	await testTeamContextResetAndUploadIsolation()
 	await testFileActionsWaitForCurrentListAndDocumentContext()
+	await testUploadedFileUsesDeleteWordingAndRefreshesAfterDelete()
 	await testSameTeamRefreshFailurePreservesExistingFilesAndCount()
 	await testTeamWebsiteInputExposesTheAuthoritativeLengthLimit()
 	await testTeamFillRendersBackgroundFilesAndBusyState()