diff --git a/api/address.js b/api/address.js
index 50022aa..7cd7b05 100644
--- a/api/address.js
+++ b/api/address.js
@@ -29,4 +29,8 @@ export const getMassageCode = (data) => {
export const setPayPassword = (data) => {
return request.post('/user/user/set_payPassword', data);
+}
+
+export const getFundList = (data) => {
+ return request.get('/user/user/fundList', data);
}
\ No newline at end of file
diff --git a/api/user.js b/api/user.js
index 7f85bac..c0d94dd 100644
--- a/api/user.js
+++ b/api/user.js
@@ -99,6 +99,10 @@ export const vipRechargeApi = (data) => {
return request.post('/store/store/recharge', data);
}
+export const reVipRechargeApi = (data) => {
+ return request.post('/store/store/again_recharge', data);
+}
+
export const rechargeCountApi = (data) => {
return request.get('/store/store/recharge_count', data);
}
@@ -137,4 +141,8 @@ export const getCreateLists = (data) => {
export const getloginSms = (data) => {
return request.post('/user/user/login_sms', data);
+}
+
+export const getReportingSms = (data) => {
+ return request.post('/user/user/reporting_sms', data);
}
\ No newline at end of file
diff --git a/components/goodPopup.vue b/components/goodPopup.vue
index 3ce66f7..f542595 100644
--- a/components/goodPopup.vue
+++ b/components/goodPopup.vue
@@ -8,13 +8,19 @@
商品名称
{{ datas.name || datas.goods_name || datas.store_name }}
+
+ 商品规格
+ {{ datas.store_info}}
+
商品单位
{{ datas.unit_name }}
商品价格
- ¥ {{ datas.price || datas.sell }} / {{ datas.unit_name }}
+ ¥ {{priceKey.off_activity==1? datas[priceKey.price]: datas[priceKey.op_price] }} /
+ {{ datas.unit_name }}
+
起批量
@@ -28,22 +34,16 @@
¥ {{ subtotal }}
-
+
购买重量*
-
-
+
+
-
+
购买数量*
-
-
-
- {{ datas.unit_name }}
-
-
+
+
@@ -80,13 +80,22 @@
},
})
+
+ let priceKey = ref({})
+ if (uni.getStorageSync('PRICE_KEY')) {
+ priceKey.value = JSON.parse(uni.getStorageSync('PRICE_KEY'));
+ } else {
+ priceKey.value = {};
+ }
+
+
const datas = ref({
cart_num: ''
});
const setData = (e) => {
datas.value = e;
if (Number(e.batch) > 0) datas.value.cart_num = e.batch;
- else datas.value.cart_num = '';
+ else datas.value.cart_num = 1;
}
@@ -107,13 +116,16 @@
}
const subtotal = computed(() => {
- let num = +datas.value.cart_num || 0;
- let sell = +datas.value.sell || +datas.value.price;
+ let num = +datas.value.cart_num || 1;
+ let sell = +datas.value[priceKey.value.off_activity == 1 ? priceKey.value.price : priceKey.value.op_price];
return Number(num * sell * 100 / 100).toFixed(2)
})
+
+
+
defineExpose({
setData,
// founcsFn
diff --git a/config/app.js b/config/app.js
index 85facca..36817f7 100644
--- a/config/app.js
+++ b/config/app.js
@@ -1,4 +1,5 @@
let BASE_URL
+let WSS_URL
import store from "@/store/user.js"
// 环境
// let env = "dev"
@@ -7,13 +8,18 @@ let env = "prod"
switch (env) {
case 'dev':
- BASE_URL = 'https://test-multi-store.lihaink.cn';
+ // BASE_URL = 'https://test-multi-store.lihaink.cn';
+ // WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
+ BASE_URL = 'https://ceshi-multi-store.lihaink.cn';
+ WSS_URL = 'wss://ceshi-multi-store.lihaink.cn/pull'
break;
case 'liu':
- BASE_URL = 'http://192.168.1.201:8545';
+ BASE_URL = 'https://ceshi-multi-store.lihaink.cn';
+ WSS_URL = 'wss://ceshi-multi-store.lihaink.cn/pull'
break;
default:
BASE_URL = 'https://multi-store.lihaink.cn';
+ WSS_URL = 'wss://multi-store.lihaink.cn/pull'
}
let HTTP_REQUEST_URL
@@ -21,6 +27,7 @@ let HEADER
let config = {
HTTP_REQUEST_URL: BASE_URL,
+ WSS_URL: WSS_URL,
HEADER: {
'content-type': 'application/json',
//#ifdef MP
diff --git a/pageQuota/balanceDetail/index.vue b/pageQuota/balanceDetail/index.vue
new file mode 100644
index 0000000..8296aaa
--- /dev/null
+++ b/pageQuota/balanceDetail/index.vue
@@ -0,0 +1,135 @@
+
+
+
+
+
+
+
+
+ {{item.title}}
+ {{ item.type=='in'?'+':'-' }}{{item.amount}}
+
+
+ {{item.create_time}}
+ 余额 {{item.before_balance}}
+
+
+
+
+
+
+ {{item.title}}
+ {{ !item.financial_pm?'+':'-' }}{{item.number}}
+
+
+ {{item.create_time}}
+
+
+
+
+
+
+ {{item.order_sn}}
+ {{ !item.status?'+':'-' }}{{item.number}}
+
+
+ {{item.create_time}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pageQuota/vipUser/index.vue b/pageQuota/vipUser/index.vue
index bcca843..b33e35d 100644
--- a/pageQuota/vipUser/index.vue
+++ b/pageQuota/vipUser/index.vue
@@ -17,61 +17,73 @@
- 开通{{Role==1?'行业会员':'商户'}}
- 已开通列表
-
+ 开通{{ Role == 1 ? '行业会员' : '商户' }}
+ 已开通列表
+
-
+
- {{Role==1?'行业会员':'商户'}}开通报备
+ {{ Role == 1 ? '行业会员' : '商户' }}开通报备
-
+
+ :customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }"
+ :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }">
-
+
+ :customStyle="{ background: '#F3F3F3', padding: '20rpx', 'border-radius': '30rpx' }"
+ :placeholderStyle="{ color: '#444444' }" :prefixIconStyle="{ 'margin-right': '40rpx' }">
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+ 重新获取({{ cutDown }})
+ {{ flag ? '获取验证码' : '重新获取' }}
+
+
+
- 报备人:{{STORE_INFO.name}}
+ 报备人:{{ STORE_INFO.name }}
-
- {{Role==1?'完成并收款':'完成'}}
+ {{ Role == 1 ? '完成并收款' : '完成' }}
@@ -82,7 +94,7 @@
当前已开通:
- 位{{Role==1?'行业会员':'商户'}}
+ 位{{ Role == 1 ? '行业会员' : '商户' }}
@@ -90,535 +102,657 @@
序号
- 行业会员
- 经营资金
- 开通时间
- 商户
- 角色
+ 行业会员
+ 经营资金
+ 开通时间
+ 商户
+ 角色
状态
-
- {{index+1}}
- {{item.real_name}}
- {{item.price}}
- {{item.create_time}}
- {{item.nickname}}
- {{item.label_name}}
+
+ {{ index + 1 }}
+ {{ item.real_name }}
+ {{ item.price }}
+ {{ item.create_time }}
+ {{ item.nickname }}
+ {{ item.label_name }}
- 已开通
- 未开通,查询
+ 已开通
+
+
+ 未开通,查询
+
+
+ 重新支付
+
+
-
-
+
-
+
+ :activeStyle="{ color: '#20B128' }">
-
-
+
- {{item.city_name}}
-
+ {{ item.city_name }}
+
-
-
- {{item.area_name}}
-
+
+
+ {{ item.area_name }}
+
-
-
- {{item.street_name}}
-
+
+
+ {{ item.street_name }}
+
-
-
- {{item.village_name}}
-
+
+
+ {{ item.village_name }}
+
-
-
- {{item.brigade_name}}
-
+
+
+ {{ item.brigade_name }}
+
-
-
+
\ No newline at end of file
diff --git a/pages.json b/pages.json
index c1ae891..0a14628 100644
--- a/pages.json
+++ b/pages.json
@@ -52,8 +52,8 @@
"path": "pages/my/my",
"style": {
"navigationBarTitleText": "个人中心",
- "enablePullDownRefresh": false,
- "navigationStyle": "custom"
+ "enablePullDownRefresh": true,
+ "navigationBarBackgroundColor": "#D3FDCA"
}
}, {
"path": "pages/charge/charge_record",
@@ -234,9 +234,14 @@
"navigationBarTitleText": "会员报备",
"enablePullDownRefresh": true
}
+ },
+ {
+ "path": "balanceDetail/index",
+ "style": {
+ "navigationBarTitleText": "余额明细",
+ "enablePullDownRefresh": true
+ }
}
-
-
]
}
],
diff --git a/pages/cart/cart.vue b/pages/cart/cart.vue
index 13f6a8b..b805550 100644
--- a/pages/cart/cart.vue
+++ b/pages/cart/cart.vue
@@ -34,9 +34,12 @@
{{item.goods_name}}
{{item.unit_name}}
+ 原价:¥{{item[priceKey.op_price]}}
+
- ¥{{item.sell}}
+ ¥{{item[priceKey.price]}}
{{item.cart_num}}
@@ -109,14 +112,11 @@
-
-
+
+
去结算({{checkAll}})
-
- ¥500起订
-
+
@@ -132,7 +132,8 @@
\ No newline at end of file
diff --git a/pages/login/login.vue b/pages/login/login.vue
index d497af0..e8420af 100644
--- a/pages/login/login.vue
+++ b/pages/login/login.vue
@@ -120,6 +120,9 @@
// 微信公众号绑定
const officialCode = () => {
+ console.log("jinfas")
+ return
+
uni.navigateTo({
url: `/pages/code/code?id=${userStore.userInfo.id}`,
success: () => {
@@ -168,7 +171,6 @@
} else {
userStore.setUserInfo(res.data);
//再次登录 已有手机号 判断是否员工
-
//身份授权成功 核销人员
if (res.data.is_staff == 1) {
userStore.setUserInfo(res.data);
@@ -209,6 +211,7 @@
}).then(res => {
//手机号获取成功 可以本地缓存用户信息以及token
userStore.setUserInfo(res.data);
+ userStore.setToken(res.data.token);
//身份授权成功 核销人员
if (res.is_staff == 1) {
userStore.setUserInfo(res.data);
diff --git a/pages/login/test.vue b/pages/login/test.vue
index 4611f40..f66e9f3 100644
--- a/pages/login/test.vue
+++ b/pages/login/test.vue
@@ -39,7 +39,8 @@
userLoginApi,
userInfoApi,
getStoreInfo,
- getloginSms
+ getloginSms,
+ loginUpdateUserApi
} from "@/api/user.js";
import {
ref,
@@ -94,10 +95,12 @@
})
uni.setStorageSync('token', res.data.token);
userStore.setToken(res.data.token);
- console.log(res.data.token)
userInfoApi().then(res => {
const user = res.data;
userStore.setUserInfo(user);
+ if (!user.openid) loginUpdateUserApi({
+ mobile: user.mobile
+ })
uni.reLaunch({
url: '/pages/index/index'
}) // 存储token到本地存储中
diff --git a/pages/my/my.vue b/pages/my/my.vue
index 7109249..190edb4 100644
--- a/pages/my/my.vue
+++ b/pages/my/my.vue
@@ -1,7 +1,7 @@
-
-
+
@@ -40,36 +40,36 @@
会员报备
+
+
+
-
+
{{userInfo.now_money||"0.00"}}
余额
-
+
{{userInfo.purchase_funds||'0.00'}}
采购款
{{userInfo.return_money||'0.00'}}
+
返还金
-
+
- {{userInfo.integral ||"0.00"}}
- 礼品券
+ {{userInfo.number ||"0.00"}}
+ 冻结礼品券
+
+
+
+ {{userInfo.GetNumber ||"0.00"}}
+ 可用礼品券
-
-
我的订单
@@ -131,13 +131,17 @@
orderCountApi
} from "@/api/order.js";
import {
- onShow
+ onShow,
+ onPullDownRefresh
} from "@dcloudio/uni-app"
+ import {
+ userInfoApi
+ } from "@/api/user.js"
+
+
const userStore = useUserStore();
-
const userInfo = ref({});
-
const orderCount = ref({
no_pay: 0,
receiving: 0,
@@ -185,9 +189,18 @@
}
onShow(() => {
- userInfo.value = userStore.userInfo;
+ userInfoApi().then(res => {
+ userInfo.value = res.data;
+ })
getOrderCount();
})
+
+ onPullDownRefresh(() => {
+ userInfoApi().then(res => {
+ userInfo.value = res.data;
+ uni.stopPullDownRefresh()
+ })
+ })
\ No newline at end of file
diff --git a/uni_modules/zy-passwordboard/components/zy-passwordboard/zy-passwordboard.vue b/uni_modules/zy-passwordboard/components/zy-passwordboard/zy-passwordboard.vue
index b9e3317..bb0db56 100644
--- a/uni_modules/zy-passwordboard/components/zy-passwordboard/zy-passwordboard.vue
+++ b/uni_modules/zy-passwordboard/components/zy-passwordboard/zy-passwordboard.vue
@@ -43,6 +43,7 @@
}
break;
}
+ uni.vibrateShort();
if (refValue.value.length === props.num) {
emits('complete', refValue.value.join(''));
}
diff --git a/utils/push.js b/utils/push.js
new file mode 100644
index 0000000..877fee4
--- /dev/null
+++ b/utils/push.js
@@ -0,0 +1,871 @@
+function Push(options) {
+ this.doNotConnect = 0;
+ options = options || {};
+ options.heartbeat = options.heartbeat || 25000;
+ options.pingTimeout = options.pingTimeout || 10000;
+ this.config = options;
+ this.uid = 0;
+ this.channels = {};
+ this.connection = null;
+ this.pingTimeoutTimer = 0;
+ Push.instances.push(this);
+ this.createConnection();
+}
+
+Push.prototype.checkoutPing = function() {
+ var _this = this;
+ _this.checkoutPingTimer && clearTimeout(_this.checkoutPingTimer);
+ _this.checkoutPingTimer = setTimeout(function() {
+ _this.checkoutPingTimer = 0;
+ if (_this.connection.state === 'connected') {
+ _this.connection.send('{"event":"pusher:ping","data":{}}');
+ if (_this.pingTimeoutTimer) {
+ clearTimeout(_this.pingTimeoutTimer);
+ _this.pingTimeoutTimer = 0;
+ }
+ _this.pingTimeoutTimer = setTimeout(function() {
+ _this.connection.closeAndClean();
+ if (!_this.connection.doNotConnect) {
+ _this.connection.waitReconnect();
+ }
+ }, _this.config.pingTimeout);
+ }
+ }, this.config.heartbeat);
+};
+
+Push.prototype.channel = function(name) {
+ return this.channels.find(name);
+};
+Push.prototype.allChannels = function() {
+ return this.channels.all();
+};
+Push.prototype.createConnection = function() {
+ if (this.connection) {
+ throw Error('Connection already exist');
+ }
+ var _this = this;
+ var url = this.config.url;
+
+ function updateSubscribed() {
+ for (var i in _this.channels) {
+ _this.channels[i].subscribed = false;
+ }
+ }
+ this.connection = new Connection({
+ url: url,
+ app_key: this.config.app_key,
+ onOpen: function() {
+ _this.connection.state = 'connecting';
+ _this.checkoutPing();
+ },
+ onMessage: function(params) {
+ if (_this.pingTimeoutTimer) {
+ clearTimeout(_this.pingTimeoutTimer);
+ _this.pingTimeoutTimer = 0;
+ }
+
+ params = JSON.parse(params.data);
+ var event = params.event;
+ var channel_name = params.channel;
+
+ if (event === 'pusher:pong') {
+ _this.checkoutPing();
+ return;
+ }
+ if (event === 'pusher:error') {
+ throw Error(params.data.message);
+ }
+ var data = JSON.parse(params.data),
+ channel;
+ if (event === 'pusher_internal:subscription_succeeded') {
+ channel = _this.channels[channel_name];
+ channel.subscribed = true;
+ channel.processQueue();
+ channel.emit('pusher:subscription_succeeded');
+ return;
+ }
+ if (event === 'pusher:connection_established') {
+ _this.connection.socket_id = data.socket_id;
+ _this.connection.updateNetworkState('connected');
+ _this.subscribeAll();
+ }
+ if (event.indexOf('pusher_internal') !== -1) {
+ console.log("Event '" + event + "' not implement");
+ return;
+ }
+ channel = _this.channels[channel_name];
+ if (channel) {
+ channel.emit(event, data);
+ }
+ },
+ onClose: function() {
+ updateSubscribed();
+ },
+ onError: function() {
+ updateSubscribed();
+ }
+ });
+};
+Push.prototype.disconnect = function() {
+ this.connection.doNotConnect = 1;
+ this.connection.close();
+};
+
+Push.prototype.subscribeAll = function() {
+ if (this.connection.state !== 'connected') {
+ return;
+ }
+ for (var channel_name in this.channels) {
+ //this.connection.send(JSON.stringify({event:"pusher:subscribe", data:{channel:channel_name}}));
+ this.channels[channel_name].processSubscribe();
+ }
+};
+
+Push.prototype.unsubscribe = function(channel_name) {
+ if (this.channels[channel_name]) {
+ delete this.channels[channel_name];
+ if (this.connection.state === 'connected') {
+ this.connection.send(JSON.stringify({
+ event: "pusher:unsubscribe",
+ data: {
+ channel: channel_name
+ }
+ }));
+ }
+ }
+};
+Push.prototype.unsubscribeAll = function() {
+ var channels = Object.keys(this.channels);
+ if (channels.length) {
+ if (this.connection.state === 'connected') {
+ for (var channel_name in this.channels) {
+ this.unsubscribe(channel_name);
+ }
+ }
+ }
+ this.channels = {};
+};
+Push.prototype.subscribe = function(channel_name) {
+ if (this.channels[channel_name]) {
+ return this.channels[channel_name];
+ }
+ if (channel_name.indexOf('private-') === 0) {
+ return createPrivateChannel(channel_name, this);
+ }
+ if (channel_name.indexOf('presence-') === 0) {
+ return createPresenceChannel(channel_name, this);
+ }
+ return createChannel(channel_name, this);
+};
+Push.instances = [];
+
+function createChannel(channel_name, push) {
+ var channel = new Channel(push.connection, channel_name);
+ push.channels[channel_name] = channel;
+ channel.subscribeCb = function() {
+ push.connection.send(JSON.stringify({
+ event: "pusher:subscribe",
+ data: {
+ channel: channel_name
+ }
+ }));
+ }
+ channel.processSubscribe();
+ return channel;
+}
+
+function createPrivateChannel(channel_name, push) {
+ var channel = new Channel(push.connection, channel_name);
+ push.channels[channel_name] = channel;
+ channel.subscribeCb = function() {
+ __ajax({
+ url: push.config.auth,
+ type: 'POST',
+ data: {
+ channel_name: channel_name,
+ socket_id: push.connection.socket_id
+ },
+ success: function(data) {
+ data = JSON.parse(data);
+ data.channel = channel_name;
+ push.connection.send(JSON.stringify({
+ event: "pusher:subscribe",
+ data: data
+ }));
+ },
+ error: function(e) {
+ throw Error(e);
+ }
+ });
+ };
+ channel.processSubscribe();
+ return channel;
+}
+
+function createPresenceChannel(channel_name, push) {
+ return createPrivateChannel(channel_name, push);
+}
+
+uni.onNetworkStatusChange(function(res) {
+ if (res.isConnected) {
+ for (var i in Push.instances) {
+ con = Push.instances[i].connection;
+ con.reconnectInterval = 1;
+ if (con.state === 'connecting') {
+ con.connect();
+ }
+ }
+ }
+});
+
+function Connection(options) {
+ this.dispatcher = new Dispatcher();
+ __extends(this, this.dispatcher);
+ var properies = ['on', 'off', 'emit'];
+ for (var i in properies) {
+ this[properies[i]] = this.dispatcher[properies[i]];
+ }
+ this.options = options;
+ this.state = 'initialized'; //initialized connecting connected disconnected
+ this.doNotConnect = 0;
+ this.reconnectInterval = 1;
+ this.connection = null;
+ this.reconnectTimer = 0;
+ this.connect();
+}
+
+Connection.prototype.updateNetworkState = function(state) {
+ var old_state = this.state;
+ this.state = state;
+ if (old_state !== state) {
+ this.emit('state_change', {
+ previous: old_state,
+ current: state
+ });
+ }
+};
+
+Connection.prototype.connect = function() {
+ this.doNotConnect = 0;
+ if (this.networkState == 'connecting' || this.networkState == 'established') {
+ console.log('networkState is ' + this.networkState + ' and do not need connect');
+ return;
+ }
+ if (this.reconnectTimer) {
+ clearTimeout(this.reconnectTimer);
+ this.reconnectTimer = 0;
+ }
+
+ this.closeAndClean();
+
+ var options = this.options;
+ var _this = this;
+ _this.updateNetworkState('connecting');
+ var cb = function() {
+ uni.onSocketOpen(function(res) {
+ _this.reconnectInterval = 1;
+ if (_this.doNotConnect) {
+ _this.updateNetworkState('closing');
+ uni.closeSocket();
+ return;
+ }
+ _this.updateNetworkState('established');
+ if (options.onOpen) {
+ options.onOpen(res);
+ }
+ });
+
+ if (options.onMessage) {
+ uni.onSocketMessage(options.onMessage);
+ }
+
+ uni.onSocketClose(function(res) {
+ _this.updateNetworkState('disconnected');
+ if (!_this.doNotConnect) {
+ _this.waitReconnect();
+ }
+ if (options.onClose) {
+ options.onClose(res);
+ }
+ });
+
+ uni.onSocketError(function(res) {
+ _this.close();
+ if (!_this.doNotConnect) {
+ _this.waitReconnect();
+ }
+ if (options.onError) {
+ options.onError(res);
+ }
+ });
+ };
+ uni.connectSocket({
+ url: options.url,
+ fail: function(res) {
+ console.log('uni.connectSocket fail');
+ console.log(res);
+ _this.updateNetworkState('disconnected');
+ _this.waitReconnect();
+ },
+ success: function() {
+
+ }
+ });
+ cb();
+}
+
+Connection.prototype.connect = function() {
+ this.doNotConnect = 0;
+ if (this.state === 'connected') {
+ console.log('networkState is "' + this.state + '" and do not need connect');
+ return;
+ }
+ if (this.reconnectTimer) {
+ clearTimeout(this.reconnectTimer);
+ this.reconnectTimer = 0;
+ }
+
+ this.closeAndClean();
+
+ var options = this.options;
+
+ this.updateNetworkState('connecting');
+
+ var _this = this;
+ var cb = function() {
+ uni.onSocketOpen(function(res) {
+ _this.reconnectInterval = 1;
+ if (_this.doNotConnect) {
+ _this.updateNetworkState('disconnected');
+ uni.closeSocket();
+ return;
+ }
+ if (options.onOpen) {
+ options.onOpen(res);
+ }
+ });
+
+ if (options.onMessage) {
+ uni.onSocketMessage(options.onMessage);
+ }
+
+ uni.onSocketClose(function(res) {
+ _this.updateNetworkState('disconnected');
+ if (!_this.doNotConnect) {
+ _this.waitReconnect();
+ }
+ if (options.onClose) {
+ options.onClose(res);
+ }
+ });
+
+ uni.onSocketError(function(res) {
+ _this.close();
+ if (!_this.doNotConnect) {
+ _this.waitReconnect();
+ }
+ if (options.onError) {
+ options.onError(res);
+ }
+ });
+ };
+ uni.connectSocket({
+ url: options.url + '/app/' + options.app_key,
+ fail: function(res) {
+ console.log('uni.connectSocket fail');
+ console.log(res);
+ _this.updateNetworkState('disconnected');
+ _this.waitReconnect();
+ },
+ success: function() {
+
+ }
+ });
+ cb();
+}
+
+Connection.prototype.closeAndClean = function() {
+ if (this.state === 'connected') {
+ uni.closeSocket();
+ }
+ this.updateNetworkState('disconnected');
+};
+
+Connection.prototype.waitReconnect = function() {
+ if (this.state === 'connected' || this.state === 'connecting') {
+ return;
+ }
+ if (!this.doNotConnect) {
+ this.updateNetworkState('connecting');
+ var _this = this;
+ if (this.reconnectTimer) {
+ clearTimeout(this.reconnectTimer);
+ }
+ this.reconnectTimer = setTimeout(function() {
+ _this.connect();
+ }, this.reconnectInterval);
+ if (this.reconnectInterval < 1000) {
+ this.reconnectInterval = 1000;
+ } else {
+ // 每次重连间隔增大一倍
+ this.reconnectInterval = this.reconnectInterval * 2;
+ }
+ // 有网络的状态下,重连间隔最大2秒
+ if (this.reconnectInterval > 2000 && navigator.onLine) {
+ _this.reconnectInterval = 2000;
+ }
+ }
+}
+
+Connection.prototype.send = function(data) {
+ if (this.state !== 'connected') {
+ console.trace('networkState is "' + this.state + '", can not send ' + data);
+ return;
+ }
+ uni.sendSocketMessage({
+ data: data
+ });
+}
+
+Connection.prototype.close = function() {
+ this.updateNetworkState('disconnected');
+ uni.closeSocket();
+}
+
+var __extends = (this && this.__extends) || function(d, b) {
+ for (var p in b)
+ if (b.hasOwnProperty(p)) {
+ d[p] = b[p];
+ }
+
+ function __() {
+ this.constructor = d;
+ }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+
+function Channel(connection, channel_name) {
+ this.subscribed = false;
+ this.dispatcher = new Dispatcher();
+ this.connection = connection;
+ this.channelName = channel_name;
+ this.subscribeCb = null;
+ this.queue = [];
+ __extends(this, this.dispatcher);
+ var properies = ['on', 'off', 'emit'];
+ for (var i in properies) {
+ this[properies[i]] = this.dispatcher[properies[i]];
+ }
+}
+
+Channel.prototype.processSubscribe = function() {
+ if (this.connection.state !== 'connected') {
+ return;
+ }
+ this.subscribeCb();
+};
+
+Channel.prototype.processQueue = function() {
+ if (this.connection.state !== 'connected' || !this.subscribed) {
+ return;
+ }
+ for (var i in this.queue) {
+ this.queue[i]();
+ }
+ this.queue = [];
+};
+
+Channel.prototype.trigger = function(event, data) {
+ if (event.indexOf('client-') !== 0) {
+ throw new Error("Event '" + event + "' should start with 'client-'");
+ }
+ var _this = this;
+ this.queue.push(function() {
+ _this.connection.send(JSON.stringify({
+ event: event,
+ data: data,
+ channel: _this.channelName
+ }));
+ });
+ this.processQueue();
+};
+
+////////////////
+var Collections = (function() {
+ var exports = {};
+
+ function extend(target) {
+ var sources = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ sources[_i - 1] = arguments[_i];
+ }
+ for (var i = 0; i < sources.length; i++) {
+ var extensions = sources[i];
+ for (var property in extensions) {
+ if (extensions[property] && extensions[property].constructor &&
+ extensions[property].constructor === Object) {
+ target[property] = extend(target[property] || {}, extensions[property]);
+ } else {
+ target[property] = extensions[property];
+ }
+ }
+ }
+ return target;
+ }
+
+ exports.extend = extend;
+
+ function stringify() {
+ var m = ["Push"];
+ for (var i = 0; i < arguments.length; i++) {
+ if (typeof arguments[i] === "string") {
+ m.push(arguments[i]);
+ } else {
+ m.push(safeJSONStringify(arguments[i]));
+ }
+ }
+ return m.join(" : ");
+ }
+
+ exports.stringify = stringify;
+
+ function arrayIndexOf(array, item) {
+ var nativeIndexOf = Array.prototype.indexOf;
+ if (array === null) {
+ return -1;
+ }
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) {
+ return array.indexOf(item);
+ }
+ for (var i = 0, l = array.length; i < l; i++) {
+ if (array[i] === item) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ exports.arrayIndexOf = arrayIndexOf;
+
+ function objectApply(object, f) {
+ for (var key in object) {
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
+ f(object[key], key, object);
+ }
+ }
+ }
+
+ exports.objectApply = objectApply;
+
+ function keys(object) {
+ var keys = [];
+ objectApply(object, function(_, key) {
+ keys.push(key);
+ });
+ return keys;
+ }
+
+ exports.keys = keys;
+
+ function values(object) {
+ var values = [];
+ objectApply(object, function(value) {
+ values.push(value);
+ });
+ return values;
+ }
+
+ exports.values = values;
+
+ function apply(array, f, context) {
+ for (var i = 0; i < array.length; i++) {
+ f.call(context || (window), array[i], i, array);
+ }
+ }
+
+ exports.apply = apply;
+
+ function map(array, f) {
+ var result = [];
+ for (var i = 0; i < array.length; i++) {
+ result.push(f(array[i], i, array, result));
+ }
+ return result;
+ }
+
+ exports.map = map;
+
+ function mapObject(object, f) {
+ var result = {};
+ objectApply(object, function(value, key) {
+ result[key] = f(value);
+ });
+ return result;
+ }
+
+ exports.mapObject = mapObject;
+
+ function filter(array, test) {
+ test = test || function(value) {
+ return !!value;
+ };
+ var result = [];
+ for (var i = 0; i < array.length; i++) {
+ if (test(array[i], i, array, result)) {
+ result.push(array[i]);
+ }
+ }
+ return result;
+ }
+
+ exports.filter = filter;
+
+ function filterObject(object, test) {
+ var result = {};
+ objectApply(object, function(value, key) {
+ if ((test && test(value, key, object, result)) || Boolean(value)) {
+ result[key] = value;
+ }
+ });
+ return result;
+ }
+
+ exports.filterObject = filterObject;
+
+ function flatten(object) {
+ var result = [];
+ objectApply(object, function(value, key) {
+ result.push([key, value]);
+ });
+ return result;
+ }
+
+ exports.flatten = flatten;
+
+ function any(array, test) {
+ for (var i = 0; i < array.length; i++) {
+ if (test(array[i], i, array)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ exports.any = any;
+
+ function all(array, test) {
+ for (var i = 0; i < array.length; i++) {
+ if (!test(array[i], i, array)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ exports.all = all;
+
+ function encodeParamsObject(data) {
+ return mapObject(data, function(value) {
+ if (typeof value === "object") {
+ value = safeJSONStringify(value);
+ }
+ return encodeURIComponent(base64_1["default"](value.toString()));
+ });
+ }
+
+ exports.encodeParamsObject = encodeParamsObject;
+
+ function buildQueryString(data) {
+ var params = filterObject(data, function(value) {
+ return value !== undefined;
+ });
+ return map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&");
+ }
+
+ exports.buildQueryString = buildQueryString;
+
+ function decycleObject(object) {
+ var objects = [],
+ paths = [];
+ return (function derez(value, path) {
+ var i, name, nu;
+ switch (typeof value) {
+ case 'object':
+ if (!value) {
+ return null;
+ }
+ for (i = 0; i < objects.length; i += 1) {
+ if (objects[i] === value) {
+ return {
+ $ref: paths[i]
+ };
+ }
+ }
+ objects.push(value);
+ paths.push(path);
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ nu = [];
+ for (i = 0; i < value.length; i += 1) {
+ nu[i] = derez(value[i], path + '[' + i + ']');
+ }
+ } else {
+ nu = {};
+ for (name in value) {
+ if (Object.prototype.hasOwnProperty.call(value, name)) {
+ nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']');
+ }
+ }
+ }
+ return nu;
+ case 'number':
+ case 'string':
+ case 'boolean':
+ return value;
+ }
+ }(object, '$'));
+ }
+
+ exports.decycleObject = decycleObject;
+
+ function safeJSONStringify(source) {
+ try {
+ return JSON.stringify(source);
+ } catch (e) {
+ return JSON.stringify(decycleObject(source));
+ }
+ }
+
+ exports.safeJSONStringify = safeJSONStringify;
+ return exports;
+})();
+
+var Dispatcher = (function() {
+ function Dispatcher(failThrough) {
+ this.callbacks = new CallbackRegistry();
+ this.global_callbacks = [];
+ this.failThrough = failThrough;
+ }
+ Dispatcher.prototype.on = function(eventName, callback, context) {
+ this.callbacks.add(eventName, callback, context);
+ return this;
+ };
+ Dispatcher.prototype.on_global = function(callback) {
+ this.global_callbacks.push(callback);
+ return this;
+ };
+ Dispatcher.prototype.off = function(eventName, callback, context) {
+ this.callbacks.remove(eventName, callback, context);
+ return this;
+ };
+ Dispatcher.prototype.emit = function(eventName, data) {
+ var i;
+ for (i = 0; i < this.global_callbacks.length; i++) {
+ this.global_callbacks[i](eventName, data);
+ }
+ var callbacks = this.callbacks.get(eventName);
+ if (callbacks && callbacks.length > 0) {
+ for (i = 0; i < callbacks.length; i++) {
+ callbacks[i].fn.call(callbacks[i].context || (window), data);
+ }
+ } else if (this.failThrough) {
+ this.failThrough(eventName, data);
+ }
+ return this;
+ };
+ return Dispatcher;
+}());
+
+var CallbackRegistry = (function() {
+ function CallbackRegistry() {
+ this._callbacks = {};
+ }
+ CallbackRegistry.prototype.get = function(name) {
+ return this._callbacks[prefix(name)];
+ };
+ CallbackRegistry.prototype.add = function(name, callback, context) {
+ var prefixedEventName = prefix(name);
+ this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
+ this._callbacks[prefixedEventName].push({
+ fn: callback,
+ context: context
+ });
+ };
+ CallbackRegistry.prototype.remove = function(name, callback, context) {
+ if (!name && !callback && !context) {
+ this._callbacks = {};
+ return;
+ }
+ var names = name ? [prefix(name)] : Collections.keys(this._callbacks);
+ if (callback || context) {
+ this.removeCallback(names, callback, context);
+ } else {
+ this.removeAllCallbacks(names);
+ }
+ };
+ CallbackRegistry.prototype.removeCallback = function(names, callback, context) {
+ Collections.apply(names, function(name) {
+ this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function(
+ oning) {
+ return (callback && callback !== oning.fn) ||
+ (context && context !== oning.context);
+ });
+ if (this._callbacks[name].length === 0) {
+ delete this._callbacks[name];
+ }
+ }, this);
+ };
+ CallbackRegistry.prototype.removeAllCallbacks = function(names) {
+ Collections.apply(names, function(name) {
+ delete this._callbacks[name];
+ }, this);
+ };
+ return CallbackRegistry;
+}());
+
+function prefix(name) {
+ return "_" + name;
+}
+
+function __ajax(options) {
+ options = options || {};
+ options.type = (options.type || 'GET').toUpperCase();
+ options.dataType = options.dataType || 'json';
+ var params = formatParams(options.data);
+
+ var xhr;
+ if (window.XMLHttpRequest) {
+ xhr = new XMLHttpRequest();
+ } else {
+ xhr = ActiveXObject('Microsoft.XMLHTTP');
+ }
+
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === 4) {
+ var status = xhr.status;
+ if (status >= 200 && status < 300) {
+ options.success && options.success(xhr.responseText, xhr.responseXML);
+ } else {
+ options.error && options.error(status);
+ }
+ }
+ }
+
+ if (options.type === 'GET') {
+ xhr.open('GET', options.url + '?' + params, true);
+ xhr.send(null);
+ } else if (options.type === 'POST') {
+ xhr.open('POST', options.url, true);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(params);
+ }
+}
+
+function formatParams(data) {
+ var arr = [];
+ for (var name in data) {
+ arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
+ }
+ return arr.join('&');
+}
+
+export default Push
\ No newline at end of file