diff --git a/common/http.interceptor.js b/common/http.interceptor.js
index d8e9b7d..649688d 100644
--- a/common/http.interceptor.js
+++ b/common/http.interceptor.js
@@ -1,7 +1,12 @@
const install = (Vue, vm) => {
+ // 请求地址
+ let baseUrl = vm.API.PRODURL;
+ if(vm.API.DEV == 'dev'){
+ baseUrl = vm.API.DEVURL;
+ };
// 请求全局配置
Vue.prototype.$u.http.setConfig({
- baseUrl: vm.API.DEVURL,
+ baseUrl: baseUrl,
method: 'POST',
dataType: 'json', // 返回数据时自动 JSON.parse()
showLoading: true, // 是否显示请求中的loading
@@ -9,14 +14,14 @@ const install = (Vue, vm) => {
loadingTime: 800 // 延迟800毫秒时显示加载框
});
- // 请求前拦截
+ // 请求前拦截, 现在不做拦截
Vue.prototype.$u.http.interceptor.request = config => {
return true;
};
// 响应拦截
Vue.prototype.$u.http.interceptor.response = res => {
- if(res.code == 200) {
+ if(res.code == 0) {
return res.result;
} else if(res.code == 201) {
console.log("其他状态:", res.code)
diff --git a/common/http.js b/common/http.js
index ae38edc..c75ad23 100644
--- a/common/http.js
+++ b/common/http.js
@@ -24,7 +24,6 @@ function getsign(params) {
return params;
}
-// TODO this获取
function $http(url, data = {}){
return new Promise((resolve, reject) => {
// 绑定this
@@ -40,10 +39,13 @@ function $http(url, data = {}){
if(!data.rand){
data.rand = Math.round(Math.random() * 1000000);
}
- // 当前请求来自的平台 TODO 动态赋值
+ // 当前请求来自的平台
data.platform = 'wxmini';
- // 当前小程序版本号 TODO 实时获取
- data.version = '1.0.0';
+ // #ifdef APP-PLUS
+ data.platform = 'app'; // 来自app平台,其他平台写法类似
+ // #endif
+ // 当前小程序版本号
+ data.version = that.API.VERSION;
// 获取设备唯一deviceId,如果没有,自动生成一个
let sysInfo = uni.getSystemInfoSync();
if(typeof sysInfo.deviceId == 'undefined'){
diff --git a/common/mixin.js b/common/mixin.js
new file mode 100644
index 0000000..ac4ad22
--- /dev/null
+++ b/common/mixin.js
@@ -0,0 +1,100 @@
+export default{
+ data(){
+ return {
+ // 返回顶部
+ needToTop: false
+ }
+ },
+ onLoad(option){
+
+ },
+ onPageScroll(res) {
+ if(res.scrollTop > 1000){
+ this.needToTop = true;
+ }
+ this.needToTop = false;
+ },
+ // 页面转发分享
+ async onShareAppMessage(res) {
+
+ },
+ methods: {
+ $check(str, type) {
+ switch (type) {
+ case 'mobile': //手机号码
+ return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
+ case 'tel': //座机
+ return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
+ case 'card': //身份证
+ return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
+ case 'mobileCode': //6位数字验证码
+ return /^[0-9]{6}$/.test(str)
+ case 'pwd': //密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
+ return /^([a-zA-Z0-9_]){6,20}$/.test(str)
+ case 'payPwd': //支付密码 6位纯数字
+ return /^[0-9]{6}$/.test(str)
+ case 'postal': //邮政编码
+ return /[1-9]\d{5}(?!\d)/.test(str);
+ case 'QQ': //QQ号
+ return /^[1-9][0-9]{4,9}$/.test(str);
+ case 'email': //邮箱
+ return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
+ case 'money': //金额(小数点2位)
+ return /^\d*(?:\.\d{0,2})?$/.test(str);
+ case 'URL': //网址
+ return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
+ case 'IP': //IP
+ return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
+ case 'date': //日期时间
+ return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/
+ .test(str)
+ case 'number': //数字
+ return /^[0-9]$/.test(str);
+ case 'english': //英文
+ return /^[a-zA-Z]+$/.test(str);
+ case 'chinese': //中文
+ return /^[\\u4E00-\\u9FA5]+$/.test(str);
+ case 'lower': //小写
+ return /^[a-z]+$/.test(str);
+ case 'upper': //大写
+ return /^[A-Z]+$/.test(str);
+ case 'HTML': //HTML标记
+ return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
+ default:
+ return true;
+ }
+ },
+ $msg(title = '', param = {}) {
+ if(!title) return;
+ uni.showToast({
+ title,
+ duration: param.duration || 1500,
+ mask: param.mask || true, // 默认应该加mask 禁止提示时操作
+ icon: param.icon || 'none'
+ });
+ },
+ $url(url, options = {}){
+ // TODO 判断登录逻辑;防抖
+ if(options.type && options.type !== ''){
+ if(options.type === 'redirect'){ // 关闭当前,跳转
+ uni.redirectTo({ url })
+ }else if(options.type === 'switch'){ // 跳转
+ uni.switchTab({ url })
+ }else if(options.type === 'launch'){ // 关闭所有,跳转
+ uni.reLaunch({ url })
+ }
+ }else{
+ uni.navigateTo({ url }) // 跳转
+ }
+ },
+ $toBack(){
+ let pages = getCurrentPages(); // 当前页
+ let beforePage = pages[pages.length - 2]; // 上个页面
+ if(beforePage && beforePage.route){
+ uni.navigateBack();
+ }else{
+ uni.switchTab({url:'/pages/index/index'});
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/main.js b/main.js
index 96c0af0..1a69262 100644
--- a/main.js
+++ b/main.js
@@ -1,10 +1,12 @@
import Vue from 'vue'
import App from './App'
+import mixin from '@/common/mixin.js';
import * as API from '@/common/api.js';
Vue.config.productionTip = false
App.mpType = 'app'
+Vue.mixin(mixin);
// 将API注入全局
Vue.prototype.API = API;
diff --git a/manifest.json b/manifest.json
index b70c1db..c27a9c2 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,5 +1,5 @@
{
- "name" : "uView-demo",
+ "name" : "shikongwang",
"appid" : "__UNI__DE5C136",
"description" : "",
"versionName" : "1.5.0",
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 1512f96..80559ff 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -29,6 +29,7 @@
{{ tab.loadingText }}
+
@@ -79,6 +80,7 @@
this.$http(this.API.API_GOODS_LIST, {data: 1}).then(res => {
console.log(res);
}).catch(err => err);
+ console.log(this.needToTop)
},
methods: {
change(index) {