| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import { SUCCESS_CODE } from '@/constants'
- import { toAnyString } from '@/utils'
- const timeout = 500
- interface ChannelItem {
- id: string
- name: string
- code: string
- description: string
- status: boolean
- createTime: string
- }
- let channelList: ChannelItem[] = [
- {
- id: toAnyString(),
- name: '微信',
- code: 'wx',
- description: '微信小程序渠道',
- status: true,
- createTime: '2024-01-01 10:00:00'
- },
- {
- id: toAnyString(),
- name: '抖音',
- code: 'douyin',
- description: '抖音小程序渠道',
- status: true,
- createTime: '2024-01-02 10:00:00'
- },
- {
- id: toAnyString(),
- name: '支付宝',
- code: 'alipay',
- description: '支付宝小程序渠道',
- status: false,
- createTime: '2024-01-03 10:00:00'
- }
- ]
- const listHandler = ({ query }) => {
- const { name, pageIndex = 1, pageSize = 10 } = query
- const filtered = channelList.filter((item) => {
- if (name && !item.name.includes(name) && !item.code.includes(name)) return false
- return true
- })
- const start = (pageIndex - 1) * pageSize
- const list = filtered.slice(start, start + pageSize)
- return { code: SUCCESS_CODE, data: { total: filtered.length, list } }
- }
- const saveHandler = ({ body }) => {
- const item: ChannelItem = {
- id: toAnyString(),
- name: body.name,
- code: body.code,
- description: body.description || '',
- status: body.status !== false,
- createTime: new Date().toLocaleString('zh-CN')
- }
- channelList.unshift(item)
- return { code: SUCCESS_CODE, data: item.id }
- }
- const updateHandler = ({ body }) => {
- const idx = channelList.findIndex((item) => item.id === body.id)
- if (idx >= 0) channelList[idx] = { ...channelList[idx], ...body }
- return { code: SUCCESS_CODE, data: 'success' }
- }
- const deleteHandler = ({ body }) => {
- const { ids } = body
- if (!ids?.length) return { code: 500, message: '请选择需要删除的数据' }
- channelList = channelList.filter((item) => !ids.includes(item.id))
- return { code: SUCCESS_CODE, data: 'success' }
- }
- export default [
- // 渠道走 Go 后端,不 mock
- ]
|