chat.ts:
import { BaseService, Service } from '../../../base'
@Service({ namespace: 'chat', url: 'learn', prefix: 'pre' })
class chat extends BaseService {
handleLoginOut(data: any) {
console.log(1)
return this.request({
url: 'http://localhost:85/api/light/user/logout',
method: 'post',
data
})
}
}
export default chat
base.ts:
import axios from 'axios'
const request = (option: any) => {
return axios(option)
}
function Service(value: { namespace?: string; url?: string; prefix?: string }) {
return function (target: any) {
target.prototype.namespace = value.namespace
if (value.url) {
target.prototype.url = value.url
}
if (value.prefix) {
target.prototype.prefix = value.prefix
}
}
}
class BaseService {
constructor(
options = {} as {
namespace?: string
url?: string
prefix?: string
}
) {
if (options?.namespace) {
// @ts-ignore
this.namespace = options.namespace
// @ts-ignore
this.url = options.url
// @ts-ignore
this.prefix = options.prefix
}
}
request(options: any = {}) {
return request(options)
}
}
export {
BaseService,
Service,
}
config.ts:
import { isFunction } from