@@ -12,11 +12,11 @@ import weekHelper from "@service/components/week-helper"
1212import limitService from "@service/limit-service"
1313import { isEffective } from "@util/limit"
1414import { useDocumentVisibility , useLocalStorage } from "@vueuse/core"
15- import { ElMessage , ElTable , ElTableColumn , ElTag , type Sort , type TableInstance } from "element-plus"
16- import { defineComponent , ref , watch } from "vue"
15+ import { ElMessage , ElSwitch , ElTable , ElTableColumn , ElTag , type Sort , type TableInstance } from "element-plus"
16+ import { defineComponent , ref , toRaw , watch } from "vue"
17+ import { verifyCanModify } from "../common"
1718import { useLimitFilter } from "../context"
1819import LimitDelayColumn from "./column/LimitDelayColumn"
19- import LimitEnabledColumn from "./column/LimitEnabledColumn"
2020import LimitOperationColumn from "./column/LimitOperationColumn"
2121import RuleContent from "./RuleContent"
2222import Waste from "./Waste"
@@ -37,6 +37,8 @@ const sortMethodByNumVal = (key: keyof timer.limit.Item & 'waste' | 'weeklyWaste
3737
3838const sortByEffectiveDays = ( { weekdays : a } : timer . limit . Item , { weekdays : b } : timer . limit . Item ) => ( a ?. length ?? 0 ) - ( b ?. length ?? 0 )
3939
40+ const sortByEnabled : CompareFn < timer . limit . Item > = ( a , b ) : number => ( a . enabled ? 1 : 0 ) - ( b . enabled ? 1 : 0 )
41+
4042const _default = defineComponent ( {
4143 emits : {
4244 delayChange : ( _row : timer . limit . Item ) => true ,
@@ -76,12 +78,21 @@ const _default = defineComponent({
7678
7779 const historySort = useLocalStorage < Sort > ( '__limit_sort_default__' , { prop : DEFAULT_SORT_COL , order : 'descending' } )
7880
81+ const onEnabledChange = async ( row : timer . limit . Item , newVal : boolean | string | number ) => {
82+ const enabled = ! ! newVal
83+ try {
84+ ! enabled && await verifyCanModify ( row )
85+ row . enabled = enabled
86+ ctx . emit ( "enabledChange" , toRaw ( row ) )
87+ } catch ( e ) {
88+ console . log ( e )
89+ }
90+ }
91+
7992 return ( ) => (
8093 < ElTable
8194 ref = { tableInstance }
82- border
83- fit
84- highlightCurrentRow
95+ border fit highlightCurrentRow
8596 style = { { width : "100%" } }
8697 data = { data . value }
8798 defaultSort = { historySort . value }
@@ -174,7 +185,18 @@ const _default = defineComponent({
174185 } }
175186 />
176187 < LimitDelayColumn onRowChange = { row => ctx . emit ( "delayChange" , row ) } />
177- < LimitEnabledColumn onRowChange = { row => ctx . emit ( "enabledChange" , row ) } />
188+ < ElTableColumn
189+ label = { t ( msg => msg . limit . item . enabled ) }
190+ minWidth = { 100 }
191+ align = "center"
192+ fixed = "right"
193+ sortable
194+ sortMethod = { sortByEnabled }
195+ >
196+ { ( { row } : ElTableRowScope < timer . limit . Item > ) => (
197+ < ElSwitch size = "small" modelValue = { row . enabled } onChange = { v => onEnabledChange ( row , v ) } />
198+ ) }
199+ </ ElTableColumn >
178200 < LimitOperationColumn
179201 onRowDelete = { deleteRow }
180202 onRowModify = { row => ctx . emit ( "modify" , row ) }
0 commit comments