123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { SUCCESS_CODE } from '@/constants'
- const timeout = 1000
- const List: {
- account: string
- pwd: string
- role: string
- roleId: string
- permissions: string | string[]
- }[] = [
- {
- account: 'admin',
- pwd: 'admin',
- role: 'admin',
- roleId: '1',
- permissions: ['*.*.*']
- },
- {
- account: 'test',
- pwd: 'test',
- role: 'test',
- roleId: '2',
- permissions: ['example:dialog:create', 'example:dialog:delete']
- }
- ]
- export default [
- // 列表接口
- {
- url: '/mock/user/list',
- method: 'get',
- response: ({ query }) => {
- const { account, pageIndex, pageSize } = query
- const mockList = List.filter((item) => {
- if (account && item.account.indexOf(account) < 0) return false
- return true
- })
- const pageList = mockList.filter(
- (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
- )
- return {
- code: SUCCESS_CODE,
- data: {
- total: mockList.length,
- list: pageList
- }
- }
- }
- },
- // 登录接口
- {
- url: '/adminapi/login',
- method: 'post',
- timeout,
- response: ({ body }) => {
- const data = body
- let hasUser = false
- for (const user of List) {
- if (user.account === data.account && user.pwd === data.pwd) {
- hasUser = true
- return {
- status: SUCCESS_CODE,
- data: user
- }
- }
- }
- if (!hasUser) {
- return {
- code: 500,
- message: '账号或密码错误'
- }
- }
- }
- },
- // 退出接口
- {
- url: '/adminapi/logout',
- method: 'post',
- timeout,
- response: () => {
- return {
- status: SUCCESS_CODE,
- data: null
- }
- }
- }
- ]
|