Преглед изворни кода

feat(forecast-summary): 添加类型定义和方法并改进错误处理

yz пре 1 месец
родитељ
комит
395903ae77
2 измењених фајлова са 23 додато и 5 уклоњено
  1. 13 5
      src/views/forecast-summary/summaryIndex.js
  2. 10 0
      src/views/forecast-summary/types.d.ts

+ 13 - 5
src/views/forecast-summary/summaryIndex.js

@@ -1,3 +1,5 @@
+// @ts-check
+
 /**
  * @typedef {import('@/api/forecast/types').ForecastSummaryQueryParams} ForecastSummaryQueryParams
  * @typedef {import('@/api/forecast/types').ForecastSummaryRecord} ForecastSummaryRecord
@@ -304,8 +306,9 @@ export default {
 
     /**
      * 搜索条件变化处理
-     * @param {Object} params - 搜索参数
-     * @param {Function} done - 完成回调
+     * @this {ForecastSummaryComponent & Vue}
+     * @param {Record<string, any>} params - 搜索参数
+     * @param {() => void} done - 完成回调
      */
     searchChange(params, done) {
       // 处理年月字段拆分
@@ -338,6 +341,7 @@ export default {
 
     /**
      * 搜索重置处理
+     * @this {ForecastSummaryComponent & Vue}
      */
     searchReset() {
       this.query = { ...DEFAULT_FORECAST_SUMMARY_QUERY }
@@ -346,7 +350,8 @@ export default {
 
     /**
      * 选择变化处理
-     * @param {Array<Object>} selection - 选中的行数据
+     * @this {ForecastSummaryComponent & Vue}
+     * @param {Array<ForecastSummaryRecord>} selection - 选中的行数据
      */
     selectionChange(selection) {
       this.selectionList = selection
@@ -354,6 +359,7 @@ export default {
 
     /**
      * 当前页变化处理
+     * @this {ForecastSummaryComponent & Vue}
      * @param {number} currentPage - 当前页码
      */
     currentChange(currentPage) {
@@ -362,6 +368,7 @@ export default {
 
     /**
      * 页大小变化处理
+     * @this {ForecastSummaryComponent & Vue}
      * @param {number} pageSize - 页大小
      */
     sizeChange(pageSize) {
@@ -370,6 +377,7 @@ export default {
 
     /**
      * 刷新处理
+     * @this {ForecastSummaryComponent & Vue}
      */
     refreshChange() {
       this.onLoad(this.page, this.query)
@@ -413,7 +421,7 @@ export default {
           this.page.currentPage = current || 1
           this.page.pageSize = size || 10
         } else {
-          this.$message.error(response?.msg || '获取数据失败')
+          this.$message.error(response?.data?.message || '获取数据失败')
           this.data = []
           this.page.total = 0
         }
@@ -439,7 +447,7 @@ export default {
         if (response && response.data && response.data.code === 200) {
           return response.data.data
         } else {
-          this.$message.error(response.data.msg || '获取详情失败')
+          this.$message.error(response.data.message || '获取详情失败')
           return null
         }
       } catch (error) {

+ 10 - 0
src/views/forecast-summary/types.d.ts

@@ -24,5 +24,15 @@ export interface ForecastSummaryComponentData {
 export interface ForecastSummaryComponent extends ForecastSummaryComponentData {
   onLoad: (page: PageConfig, params?: Record<string, any>) => Promise<void>
   getForecastSummaryDetail: (id: string | number) => Promise<ForecastSummaryRecord | null>
+  searchChange: (params: Record<string, any>, done: () => void) => void
+  searchReset: () => void
+  selectionChange: (selection: Array<ForecastSummaryRecord>) => void
+  currentChange: (currentPage: number) => void
+  sizeChange: (pageSize: number) => void
+  refreshChange: () => void
+  getApprovalStatusConfig: (status: number) => { label: string; type: string }
+  formatNumber: (value: string | number) => string
+  formatDateTime: (dateTime: string) => string
+  formatYearMonth: (year: number, month: number) => string
   $message: MessageInstance
 }