first commit
This commit is contained in:
14
app-sqlite-master/app-sqlite/common/lib/config.js
Normal file
14
app-sqlite-master/app-sqlite/common/lib/config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export default {
|
||||
// #ifndef H5
|
||||
baseUrl:"http://192.168.100.12:8000",
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
baseUrl:"http://192.168.100.12:8000",
|
||||
// #endif
|
||||
|
||||
version: "/v1",
|
||||
|
||||
env:"dev",
|
||||
appId: 10000
|
||||
}
|
||||
95
app-sqlite-master/app-sqlite/common/lib/request.js
Normal file
95
app-sqlite-master/app-sqlite/common/lib/request.js
Normal file
@@ -0,0 +1,95 @@
|
||||
import $C from './config.js';
|
||||
import $U from './util.js';
|
||||
|
||||
export default {
|
||||
// 全局配置
|
||||
common:{
|
||||
baseUrl:$C.baseUrl + $C.version,
|
||||
header:{
|
||||
'Content-Type':'application/json;charset=UTF-8',
|
||||
},
|
||||
data:{},
|
||||
method:'GET',
|
||||
dataType:'json',
|
||||
token:true,
|
||||
},
|
||||
// 请求 返回promise
|
||||
request(options = {}){
|
||||
// 组织参数
|
||||
options.url = this.common.baseUrl + options.url
|
||||
options.header = options.header || this.common.header
|
||||
options.data = options.data || this.common.data
|
||||
options.method = options.method || this.common.method
|
||||
options.dataType = options.dataType || this.common.dataType
|
||||
options.token = options.token === false ? false : this.common.token
|
||||
// params
|
||||
options.url = options.url + "?appId=10000"
|
||||
console.log(options.url)
|
||||
|
||||
// 请求
|
||||
return new Promise((res,rej)=>{
|
||||
// 请求中...
|
||||
uni.request({
|
||||
...options,
|
||||
success: (result) => {
|
||||
// 返回原始数据
|
||||
if(options.native){
|
||||
return res(result)
|
||||
}
|
||||
console.log(result.statusCode)
|
||||
// 服务端失败
|
||||
if(result.statusCode !== 200){
|
||||
if (options.toast !== false) {
|
||||
uni.showToast({
|
||||
title: result.data.data || '服务端失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
return rej(result.data)
|
||||
}
|
||||
// 其他验证...
|
||||
// 成功
|
||||
let data = result.data
|
||||
|
||||
res(data)
|
||||
},
|
||||
fail: (error) => {
|
||||
uni.showToast({ title: error.errMsg || '请求失败', icon: 'none' });
|
||||
return rej(error)
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
setQueryConfig(params){
|
||||
var _str = "?";
|
||||
for(var o in params){
|
||||
if(params[o] != -1){
|
||||
_str += o + "=" + params[o] + "&";
|
||||
}
|
||||
}
|
||||
var _str = _str.substring(0, _str.length-1); //末尾是&
|
||||
return _str;
|
||||
},
|
||||
// get请求
|
||||
get(url,data = {},options = {}){
|
||||
options.url = url
|
||||
options.data = data
|
||||
options.method = 'GET'
|
||||
return this.request(options)
|
||||
},
|
||||
// post请求
|
||||
post(url,data = {},options = {}){
|
||||
options.url = url
|
||||
options.data = data
|
||||
options.method = 'POST'
|
||||
console.log(options)
|
||||
return this.request(options)
|
||||
},
|
||||
// delete请求
|
||||
del(url,data = {},options = {}){
|
||||
options.url = url
|
||||
options.data = data
|
||||
options.method = 'DELETE'
|
||||
return this.request(options)
|
||||
}
|
||||
}
|
||||
44
app-sqlite-master/app-sqlite/common/lib/util.js
Normal file
44
app-sqlite-master/app-sqlite/common/lib/util.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import $C from './config.js'
|
||||
export default {
|
||||
// 获取存储列表数据
|
||||
getStorage(key){
|
||||
let data = null;
|
||||
// #ifdef H5
|
||||
if($C.env === 'dev'){
|
||||
data = window.sessionStorage.getItem(key)
|
||||
} else {
|
||||
data = uni.getStorageSync(key)
|
||||
}
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
data = uni.getStorageSync(key)
|
||||
// #endif
|
||||
return data
|
||||
},
|
||||
// 设置存储
|
||||
setStorage(key,data){
|
||||
// #ifdef H5
|
||||
if($C.env === 'dev'){
|
||||
return window.sessionStorage.setItem(key,data)
|
||||
} else {
|
||||
return uni.setStorageSync(key,data)
|
||||
}
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
return uni.setStorageSync(key,data)
|
||||
// #endif
|
||||
},
|
||||
// 删除存储
|
||||
removeStorage(key){
|
||||
// #ifdef H5
|
||||
if($C.env === 'dev'){
|
||||
return window.sessionStorage.removeItem(key);
|
||||
} else {
|
||||
return uni.removeStorageSync(key)
|
||||
}
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
return uni.removeStorageSync(key)
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user