import { post , get , put , _delete } from '@/lin/plugins/axios' ; import { IAllPermissions , IAdminUsers , IGroupItem , IGroupItemWithPermissions , IResponseWithoutData , } from '@/types/model' ; const EE = 0 , UCOUNT = 10 , LPAGE = 0 , GCOUNT = 5 ; export default class Admin { ee : number ; uCount : number ; lPage : number ; gCount : number ; constructor ( ee = EE , uCount = UCOUNT , gPage = LPAGE , gCount = GCOUNT ) { this . ee = ee ; this . uCount = uCount ; this . lPage = gPage ; this . gCount = gCount ; } async increaseee ( ) { this . ee += 1 ; } async increaseGpage ( ) { this . lPage += 1 ; } async decreaseee ( ) { this . ee -= 1 ; if ( this . ee < 0 ) { this . ee = 0 ; } } async decreaseGpage ( ) { this . lPage -= 1 ; if ( this . lPage < 0 ) { this . lPage = 0 ; } } static getAllPermissions ( ) { return get ( 'cms/admin/permission' ) ; } static async getAdminUsers ( { group_id , count = UCOUNT , page = EE , } ) { let res ; if ( group_id ) { res = await get ( 'cms/admin/users' , { count , page , group_id } ) ; } else { res = await get ( 'cms/admin/users' , { count , page } ) ; } return res ; } async nextUsersPage ( ) { await this . increaseee ( ) ; return Admin . getAdminUsers ( { } ) ; } async preUsersPage ( ) { await this . decreaseee ( ) ; return Admin . getAdminUsers ( { } ) ; } static async getAllGroups ( ) { const groups = await get ( 'cms/admin/group/all' ) ; return groups ; } static async getOneGroup ( id ) { const group = await get ( `cms/admin/group/${ id }` ) ; return group ; } static async createOneGroup ( name , info , permission_ids ) { const res = await post ( 'cms/admin/group' , { name , info , permission_ids } ) ; return res ; } static async updateOneGroup ( name , info , id ) { const res = await put ( `cms/admin/group/${ id }` , { name , info } ) ; return res ; } static async deleteOneGroup ( id ) { const res = await _delete ( `cms/admin/group/${ id }` ) ; return res ; } static async deleteOneUser ( id ) { const res = await _delete ( `cms/admin/user/${ id }` ) ; return res ; } static async updateOneUser ( email , group_ids , id ) { const res = await put ( `cms/admin/user/${ id }` , { email , group_ids } ) ; return res ; } static async dispatchPermissions ( group_id , permission_ids ) { const res = await post ( 'cms/admin/permission/dispatch/batch' , { group_id , permission_ids } ) ; return res ; } static async changePassword ( new_password , confirm_password , id ) { const res = await put ( `cms/admin/user/${ id }/password` , { new_password , confirm_password } ) ; return res ; } static async removePermissions ( group_id , permission_ids ) { const res = await post ( 'cms/admin/permission/remove' , { group_id , permission_ids } ) ; return res ; } }