123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- // var siteConfig = {
- // uniacid: 19,
- // siteroot: "https://ins.iduomi.cc/addons/wike_chatgpt/public/index.php/",
- // root: "https://ins.iduomi.cc/addons/wike_chatgpt/public/",
- // };
- // var siteConfig = {
- // uniacid: 2,
- // siteroot: "https://dev.iduomi.cc/addons/wike_chatgpt/public/index.php/",
- // root: "https://dev.iduomi.cc/addons/wike_chatgpt/public/",
- // };
- // var siteConfig = {
- // uniacid: 5059,
- // siteroot: "http://nywhcm.com/addons/wike_aging/public/index.php/",
- // root: "http://nywhcm.com/addons/wike_aging/public/",
- // };
- // var siteConfig = {
- // uniacid: 1,
- // siteroot: "https://ins.iduomi.cc/addons/wike_chatgpt/public/index.php/",
- // root: "https://ins.iduomi.cc/addons/wike_chatgpt/public/",
- // };
- var siteConfig = {
- uniacid: 1,
- siteroot: "http://t20.9026.com/",
- root: "http://t20.9026.com/"
- };
- let siteInfo = siteConfig;
- let uniacid = 1;
- // if (siteInfo.uniacid) {
- // uni.setStorageSync('uniacid', siteInfo.uniacid);
- // uniacid = siteInfo.uniacid
- // } else {
- // uniacid = uni.getStorageSync('uniacid')
- // }
- export const API_ROOT = `${siteInfo.root}`; //后台接口域名
- export const API_URL = `${siteInfo.root}`; //后台接口域名
- export const UNIACID = `${uniacid}`;
- export const IMG_URL = `${siteInfo.root}static/mobile/images`;
- export function apiurl(action) {
- return 'http://t20.9026.com/api';
- }
- import platform from '@/common/platform/index';
- export default class Request {
- constructor() {
- // console.log('uniacid:'+uniacid);
- // 默认配置
- this.config = {
- baseUrl: siteInfo.siteroot,
- header: {
- 'content-type': 'application/json',
- 'platform': platform.get(),
- 'uniacid': uniacid,
- 'Authorization': uni.getStorageSync('token')
- },
- url: '',
- data: {},
- params: {},
- method: 'GET',
- dataType: 'json',
- // #ifndef MP-ALIPAY || APP-PLUS
- responseType: 'text',
- // #endif
- custom: {},
- // #ifdef APP-PLUS
- sslVerify: false
- // #endif
- }
- /* 拦截器 */
- this.interceptor = {
- request: cb => {
- if (cb) {
- this.requestBefore = cb
- } else {
- this.requestBefore = request => request
- }
- },
- response: (cb) => {
- if (cb) {
- this.requestAfter = cb
- } else {
- this.requestAfter = response => response
- }
- }
- }
- }
- /* 判断url是否完整 */
- static isUrl(url) {
- return true
- }
- static addQueryString(params) {
- let paramsData = ''
- Object.keys(params).forEach(key => {
- paramsData += key + '=' + encodeURIComponent(params[key]) + '&'
- })
- return paramsData.substring(0, paramsData.length - 1)
- }
- /* 请求前 */
- static requestBefore(config) {
- return config
- }
- /* 请求后 */
- static requestAfter(response) {
- return response
- }
- /*设置全局配置*/
- setConfig(func) {
- return func(this.config)
- }
- /**
- * @Function
- * @param {Object} options - 请求配置项
- * @prop {String} options.url - 请求路径
- * @prop {Object} options.data - 请求参数
- * @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
- * @prop {Object} [options.dataType = config.dataType] - 如果设为 json,会尝试对返回的数据做一次 JSON.parse
- * @prop {Object} [options.header = config.header] - 请求header
- * @prop {Object} [options.method = config.method] - 请求方法
- * @returns {Promise<unknown>}
- */
- async request(options = {}) {
- options = {
- ...options,
- ...this.config,
- ...this.requestBefore(options)
- }
- return new Promise((resolve, reject) => {
- let mergeUrl = 'http://t20.9026.com/api/order/course/list';
- if (JSON.stringify(options.params) !== '{}') {
- let query = Request.addQueryString(options.params);
- mergeUrl += mergeUrl.indexOf('?') === -1 ? `?${query}` : `&${query}`
- }
- options.url = mergeUrl
- options.success = res => {
- resolve(this.requestAfter(res.data))
- }
- options.fail = err => {
- reject(this.requestAfter(err))
- }
- uni.request(options)
- })
- }
- get(url, options = {}) {
- return this.request({
- url,
- method: 'GET',
- ...options
- })
- }
- post(url, data, options = {}) {
- return this.request({
- url,
- data,
- method: 'POST',
- ...options
- })
- }
- }
|