Ver Fonte

fix(report): disable actions while generating

Developer há 1 mês atrás
pai
commit
61c94ecd9f

+ 50 - 19
pagesHome/components/report/generateList.vue

@@ -40,8 +40,9 @@
 							<view class="gbox-item-bottom-right" @click="sendReport(item)" v-if="item.state!=-1">发送报告</view>
 							<view class="gbox-item-bottom-right" @click="reSendReport(item)" v-if="item.state==-1">重新生成</view>
 						</view>
-					</view>
-				</view>
+					</view>
+					<view class="gbox-item-generating-mask" v-if="isReportGenerating(item)" @click.stop="showGeneratingReminder"></view>
+				</view>
 			</u-list-item>
 		</u-list>
 		<view class="kind-reminder adffcacjc" v-if="testShow">
@@ -86,7 +87,7 @@
 <script>
 	import { getPlatformInfo } from '@/utils/platform.js'; 
 	import { reportArtifactUrl, reportArtifactDownloadUrl } from '@/utils/reportArtifactLinks.js'
-	import { canEditEvaluation, EVALUATION_PROCESSING_PROMPT, normalizeEvaluationForm } from '@/utils/reportEvaluationEdit.js'
+	import { canEditEvaluation, isReportGenerating, EVALUATION_PROCESSING_PROMPT, normalizeEvaluationForm } from '@/utils/reportEvaluationEdit.js'
 	import CusSelectTeamUser from '@/components/CusSelectTeamUser/index.vue'
 	export default {
 		props:{
@@ -127,7 +128,18 @@
 				evaluationForm:{overallAssessment:'',developmentAdvice:''}
 			}
 		},
-		methods:{
+		methods:{
+			isReportGenerating(item){
+				return isReportGenerating(item);
+			},
+			showGeneratingReminder(){
+				this.$showToast('报告正在生成中,暂不可操作,请稍候。');
+			},
+			guardReportOperation(item){
+				if(!this.isReportGenerating(item)) return true;
+				this.showGeneratingReminder();
+				return false;
+			},
 			scrolltolower(){
 				this.$emit('scrolltolower')
 			},
@@ -140,8 +152,9 @@
 					})
 				})
 			},
-			async forwardReport(item){
-				//发送给账号自己的邮箱
+			async forwardReport(item){
+				if(!this.guardReportOperation(item)) return;
+				//发送给账号自己的邮箱
 				if(!uni.getStorageSync('userInfo')||!JSON.parse(uni.getStorageSync('userInfo')).email) return this.$showModal('发送邮件前请先在我的-设置-用户信息中绑定邮箱')
 				uni.showModal({
 					title:'温馨提示',
@@ -199,6 +212,7 @@
 				return canEditEvaluation(item);
 			},
 			openEvaluation(item){
+				if(!this.guardReportOperation(item)) return;
 				if(!this.canEditEvaluation(item)) return;
 				this.evaluationReportId = item.reportId;
 				this.evaluationSubmitting = false;
@@ -228,7 +242,8 @@
 				}).finally(()=>{ this.evaluationSubmitting = false; });
 			},
 			sendConfirm(){
-				if(this.teamUserList.filter(t=>t.select).length===0) return this.$showToast('请选择要发送的用户')
+				if(!this.guardReportOperation(this.selectItem)) return;
+				if(this.teamUserList.filter(t=>t.select).length===0) return this.$showToast('请选择要发送的用户')
 				if(this.sendType===1&&(!uni.getStorageSync('userInfo')||!JSON.parse(uni.getStorageSync('userInfo')).email)) return this.$showModal('发送前请先在我的-设置-用户信息中绑定邮箱')
 				
 				if(this.sendType===1){
@@ -261,6 +276,7 @@
 				this.$refs.selectTeamUser.selectAll = false;
 			},
 			reviewArtifact(item, kind){
+				if(!this.guardReportOperation(item)) return;
 				const url = reportArtifactUrl(item, kind)
 				if(!url) return this.$showToast('该报告尚未生成,请稍后再试。')
 				const { isPC, isMobile, platform } = getPlatformInfo();
@@ -310,13 +326,15 @@
 				const path = (fileUrl || '').split('?')[0].toLowerCase()
 				return path.endsWith('.docx') ? 'docx' : 'pdf'
 			},
-			askReport(item){
-				uni.navigateTo({
+			askReport(item){
+				if(!this.guardReportOperation(item)) return;
+				uni.navigateTo({
 					url:`/pages/reportAsk?pdfUrl=${item.fileUrl}&fileName=${this.typeCfg[item.type]||'个人版'}-${item.reportName}`
 				})
 			},
-			async sendReport(item){
-				if(!item.fileUrl) return this.$showModal('该报告尚未生成PDF文件,请等待生成后发送。')
+			async sendReport(item){
+				if(!this.guardReportOperation(item)) return;
+				if(!item.fileUrl) return this.$showModal('该报告尚未生成PDF文件,请等待生成后发送。')
 				
 				this.sendType = 2;
 				this.$refs.selectTeamUser.title = '发送报告'
@@ -332,8 +350,9 @@
 					this.teamUserShow = true;
 				})
 			},
-			reSendReport(item){
-				this.$api.get(`/core/report/regenerateReport/${item.reportId}`).then(({data:res})=>{
+			reSendReport(item){
+				if(!this.guardReportOperation(item)) return;
+				this.$api.get(`/core/report/regenerateReport/${item.reportId}`).then(({data:res})=>{
 					if(res.code!==0) return this.$showToast(res.msg)
 					this.$emit('reSendReport')
 				})
@@ -346,12 +365,24 @@
 		@import '../../../static/_asset-config';
 .gbox{
 		height: 100%;
-		&-item{
-			margin-top: 20rpx;
-			background: #FFFFFF;
-			border-radius: 24rpx;
-			padding: 40rpx 20rpx 20rpx;
-			&-top{
+	&-item{
+			margin-top: 20rpx;
+			background: #FFFFFF;
+			border-radius: 24rpx;
+			padding: 40rpx 20rpx 20rpx;
+			position: relative;
+
+			&-generating-mask{
+				position: absolute;
+				left: 0;
+				right: 0;
+				top: 0;
+				bottom: 0;
+				z-index: 10;
+				border-radius: 24rpx;
+				background: rgba(255, 255, 255, .35);
+			}
+			&-top{
 				&-type{
 					width: 98rpx;
 					height: 36rpx;

+ 4 - 0
tests/reportButtonAvailability.test.js

@@ -3,6 +3,10 @@ const fs = require('fs');
 
 const source = fs.readFileSync('pagesHome/components/report/generateList.vue', 'utf8');
 
+assert.match(source, /isReportGenerating\(item\)/);
+assert.match(source, /showGeneratingReminder/);
+assert.match(source, /guardReportOperation\(item\)/);
+
 assert.match(
   source,
   /class="gbox-item-bottom-right report-button-disabled"\s+@click="showReportUnavailable\('background'\)"/

+ 4 - 1
tests/reportEvaluationEdit.test.js

@@ -1,9 +1,12 @@
 const assert = require('node:assert/strict')
-const { canEditEvaluation, EVALUATION_PROCESSING_PROMPT, normalizeEvaluationForm } = require('../utils/reportEvaluationEdit')
+const { canEditEvaluation, isReportGenerating, EVALUATION_PROCESSING_PROMPT, normalizeEvaluationForm } = require('../utils/reportEvaluationEdit')
 
 assert.equal(canEditEvaluation({ reportType: '1', state: 1, status: 'SUCCEEDED' }), true)
 assert.equal(canEditEvaluation({ reportType: '1', state: 0, status: 'RUNNING' }), false)
 assert.equal(canEditEvaluation({ reportType: '2', state: 1, status: 'SUCCEEDED' }), false)
+assert.equal(isReportGenerating({ state: 0 }), true)
+assert.equal(isReportGenerating({ state: 1, status: 'RUNNING' }), true)
+assert.equal(isReportGenerating({ state: 1, status: 'SUCCEEDED' }), false)
 assert.deepEqual(normalizeEvaluationForm({ overallAssessment: '评估', developmentAdvice: '建议' }), {
 	overallAssessment: '评估', developmentAdvice: '建议'
 })

+ 6 - 1
utils/reportEvaluationEdit.js

@@ -1,5 +1,10 @@
 const EVALUATION_PROCESSING_PROMPT = '评估分析正在进行中,你需要等待1小时左右,我们会在报告生成完成后提示你,你可以去“我的PERILL报告”查阅报告结果。'
 
+function isReportGenerating(item = {}) {
+	item = item || {}
+	return String(item.state) === '0' || ['RUNNING', 'PENDING'].indexOf(String(item.status || '')) !== -1
+}
+
 function canEditEvaluation(item = {}) {
 	const reportState = item.reportState === undefined || item.reportState === null ? item.state : item.reportState
 	return String(item.reportType || '') === '1' && String(reportState) === '1'
@@ -13,4 +18,4 @@ function normalizeEvaluationForm(data = {}) {
 	}
 }
 
-module.exports = { EVALUATION_PROCESSING_PROMPT, canEditEvaluation, normalizeEvaluationForm }
+module.exports = { EVALUATION_PROCESSING_PROMPT, isReportGenerating, canEditEvaluation, normalizeEvaluationForm }