import { get } from '@/lin/plugins/axios' ; import { ILogUsers , ILogsInfo } from '@/types/model' ; class Log { name : string | undefined ; start : string | undefined ; end : string | undefined ; keyword : string ; uPage : number ; uCount : number ; lPage : number ; lCount : number ; sPage : number ; sCount : number ; constructor ( { uPage = 0 , uCount = 5 , lPage = 0 , lCount = 15 , sPage = 0 , sCount = 15 , } ) { if ( uPage === 0 ) { this . uPage = uPage ; } if ( uCount ) { this . uCount = uCount ; } if ( lPage === 0 ) { this . lPage = lPage ; } if ( lCount ) { this . lCount = lCount ; } if ( sPage === 0 ) { this . sPage = sPage ; } if ( sCount ) { this . sCount = sCount ; } } async increaseUpage ( ) { this . uPage += 1 ; } async increaseLpage ( ) { this . lPage += 1 ; } increaseSpage ( ) { this . sPage += 1 ; } init ( ) { this . lPage = 0 ; this . uPage = 0 ; this . sPage = 0 ; } setBaseInfo ( name ? , start ? , end ? ) { this . name = name ; this . start = start ; this . end = end ; } setKeyword ( keyword ) { this . keyword = keyword ; } param { number } count param { number } page async getLoggedUsers ( { count , page , } ) { const users = await get ( 'cms/log/users' , { count : count || this . uCount , page : page || this . uPage } ) ; return users ; } param { number } count param { number } page param { number } name param { number } start param { number } end async getLogs ( { count , page , name , start , end , next = false , } ) { try { if ( ! next ) { this . setBaseInfo ( name , start , end ) ; } if ( page === 0 ) { this . lPage = 0 ; } const res = await get ( 'cms/log' , { count : count || this . lCount , page : page || this . lPage , name : name || this . name , start : start || this . start , end : end || this . end } ) ; return res ; } catch ( err ) { console . log ( 'error' , err ) ; } } param { number } count param { number } page param { number } keyword param { number } name param { number } start param { number } end async searchLogs ( { count , page , keyword , name , start , end , next = false , } ) { if ( ! next ) { this . setBaseInfo ( name , start , end ) ; this . setKeyword ( keyword || '' ) ; } if ( page === 0 ) { this . sPage = 0 ; } try { const res = await get ( 'cms/log/search' , { count : count || this . sCount , page : page || this . sPage , keyword : keyword || this . keyword || '' , name : name || this . name || null , start : start || this . start || null , end : end || this . end || null } ) ; return res ; } catch ( err ) { console . log ( err ) ; } } moreLogPage ( ) { this . increaseLpage ( ) ; return this . getLogs ( { next : true } ) ; } moreSearchPage ( ) { this . increaseSpage ( ) ; return this . searchLogs ( { next : true } ) ; } } export default new Log ( { } ) ;