123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- const platform = uni.getSystemInfoSync().platform
- var base_url = 'https://hire.hdlkeji.com'
- export default {
- config: {
- baseUrl: base_url,
- headers: {
- "content-type": "application/json",
- "Token": uni.getStorageSync('token') ? uni.getStorageSync('token') : ''
-
- },
- dataType: "json",
- responseType: "text"
- },
- interceptor: {
- request: function(_config) {},
- response: null
- },
- request(options) {
-
-
-
-
- return new Promise((resolve, reject) => {
- let _config = null
- options.url = this.config.baseUrl + options.url
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- options.header = {
- "content-type": "application/json",
- "Token": uni.getStorageSync('token') ? uni.getStorageSync('token') : ''
- }
- options.fail = (response) => {
- uni.showToast({
- icon: "none",
- title: '网络连接失败,请检查网络'
- })
- reject(response)
- }
- options.complete = (response) => {
- response.config = _config
- if (response.statusCode === 200 || response.statusCode === 201) {
- resolve(response.data);
- } else {
- if (response.statusCode === 404) {
- uni.showToast({
- icon: "none",
- title: '接口不存在'
- })
- }
- if (response.statusCode === 500) {
- uni.showToast({
- icon: "none",
- title: '服务器错误'
- })
- }
- reject(response)
- }
- }
- _config = Object.assign({}, this.config, options)
- _config.requestId = new Date().getTime()
- if (this.interceptor.request) {
- this.interceptor.request(_config)
- }
- uni.request(_config);
- });
- },
- get(url, data, showtips, options) {
- data = data ? data : {};
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.header = {}
- options.method = 'GET'
- options.showtips = showtips
- return this.request(options)
- },
- post(url, data, showtips, options) {
- data = data ? data : {};
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.header = {}
- options.method = 'POST'
- options.showtips = showtips
- return this.request(options)
- },
- put(url, data, showtips, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.method = 'PUT'
- options.showtips = showtips
- return this.request(options)
- },
- del(url, data, showtips, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.showtips = showtips
- options.method = 'DELETE'
- return this.request(options)
- }
- }
|