From 57fa7980cf25caad28486983576320f80024873d Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Mon, 24 Jun 2024 14:07:32 +0800
Subject: [PATCH 01/27] ad
---
config/app.js | 4 ++--
pages/index/index.vue | 34 +++++++++++++---------------------
2 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/config/app.js b/config/app.js
index 85facca..ab2ac5f 100644
--- a/config/app.js
+++ b/config/app.js
@@ -1,8 +1,8 @@
let BASE_URL
import store from "@/store/user.js"
// 环境
-// let env = "dev"
-let env = "prod"
+let env = "dev"
+// let env = "prod"
// let env = "liu";
switch (env) {
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 254ab6f..955ee96 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -247,8 +247,8 @@
import useUserStore from "@/store/user";
const userStore = useUserStore();
const STORE_INFO = reactive({
- id: 23,
- store_name: "农(特)产品直营店"
+ id: '',
+ store_name: ""
})
const getStoreInfoFn = () => {
@@ -370,8 +370,7 @@
name: '',
order: '',
store_name: '',
- // store_id: 23
- store_id: 4
+ store_id: ''
})
const loading = ref(true);
@@ -387,8 +386,7 @@
if (class_all) class_id = ""; //只能带其中一个
if (loadmore) where.value.page_no++;
else where.value.page_no = 1;
- // where.value.store_id = 23
- where.value.store_id = 4
+ console.log('where------------', where.value)
goodListApi({
...where.value,
class_all: class_all,
@@ -397,11 +395,6 @@
}).then(res => {
if (loadmore) goodList.value.push(...res.data.lists);
else goodList.value = res.data.lists;
- // 补充店铺信息
- // if (!STORE_INFO.store_name || !STORE_INFO.detailed_address) {
- // STORE_INFO.store_name = res.data.store.name;
- // STORE_INFO.value.detailed_address = res.data.store.detailed_address;
- // }
})
}
@@ -423,9 +416,7 @@
page_no: page_no,
page_size: 30,
level: three,
- // store_id: STORE_INFO.id // 店铺id,用于获取店铺分类列表,如果为空则获取全部分类列表,否则获取店铺分类列表。
- // store_id: 23 // 店铺id,用于获取店铺分类列表,如果为空则获取全部分类列表,否则获取店铺分类列表。
- store_id: 4 // 店铺id,用于获取店铺分类列表,如果为空则获取全部分类列表,否则获取店铺分类列表。
+ store_id: STORE_INFO.id // 店铺id,用于获取店铺分类列表,如果为空则获取全部分类列表,否则获取店铺分类列表。
}).then(res => {
if (pid == 0) { // 加载一级分类时设置全部分类
if (!res.data?.lists?.length) return;
@@ -527,10 +518,7 @@
const openGoodPopup = (item) => { // 打开数量/重量弹窗
goodData.value = item;
goodRef.value.setData(item);
- // goodRef.value.founcsFn();
showGoodPopup.value = true;
-
-
//统计商品的访问记录
productLogApi({
product_id: item.product_id,
@@ -609,13 +597,17 @@
getShareInfo()
onLoad(async (opt) => {
- where.value.store_id = opt.id || STORE_INFO.id;
- // 店铺id
if (opt.id) {
+ where.value.store_id = (opt.id == 'undefined' ? STORE_INFO.id : opt.id);
+ } else {
+ where.value.store_id = STORE_INFO.id
+ }
+ // 店铺id
+ if (opt.id && opt.id != 'undefined') {
+ console.log(opt.id, opt.id != 'undefined', "进来了这里")
where.value.store_id = opt.id;
const info = await shopDetailApi({
- store_id: 4
- // store_id: 23
+ store_id: where.value.store_id
});
// 分享参数至当前用户参数
if (opt.spread_uid) {
From 9086ccd76fbc193ec027a870fe7825edf68bcdff Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Mon, 24 Jun 2024 14:20:47 +0800
Subject: [PATCH 02/27] add
---
pages/index/index.vue | 1 -
pages/login/test.vue | 1 -
2 files changed, 2 deletions(-)
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 955ee96..93ae8a3 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -386,7 +386,6 @@
if (class_all) class_id = ""; //只能带其中一个
if (loadmore) where.value.page_no++;
else where.value.page_no = 1;
- console.log('where------------', where.value)
goodListApi({
...where.value,
class_all: class_all,
diff --git a/pages/login/test.vue b/pages/login/test.vue
index 4611f40..32c2ed4 100644
--- a/pages/login/test.vue
+++ b/pages/login/test.vue
@@ -94,7 +94,6 @@
})
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);
From edb5d70e9a95495dd6dea9939bfbb44284198bcc Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Mon, 24 Jun 2024 15:03:11 +0800
Subject: [PATCH 03/27] add
---
api/address.js | 4 ++
pageQuota/balanceDetail/index.vue | 83 +++++++++++++++++++++++++++++++
pages.json | 9 +++-
pages/index/index.vue | 7 ++-
pages/login/test.vue | 6 ++-
pages/my/my.vue | 8 +--
6 files changed, 109 insertions(+), 8 deletions(-)
create mode 100644 pageQuota/balanceDetail/index.vue
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/pageQuota/balanceDetail/index.vue b/pageQuota/balanceDetail/index.vue
new file mode 100644
index 0000000..47c6ca0
--- /dev/null
+++ b/pageQuota/balanceDetail/index.vue
@@ -0,0 +1,83 @@
+
+
+ {{mark}}
+
+
+
+
+
+ 余额宝自动转入
+ -204.00
+
+
+ 2024-10-21
+ 余额 204.00
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages.json b/pages.json
index c1ae891..2db36bc 100644
--- a/pages.json
+++ b/pages.json
@@ -234,9 +234,14 @@
"navigationBarTitleText": "会员报备",
"enablePullDownRefresh": true
}
+ },
+ {
+ "path": "balanceDetail/index",
+ "style": {
+ "navigationBarTitleText": "余额明细",
+ "enablePullDownRefresh": true
+ }
}
-
-
]
}
],
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 93ae8a3..749cef2 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -232,7 +232,8 @@
import {
productLogApi,
userInfoApi,
- getStoreInfo
+ getStoreInfo,
+ loginUpdateUserApi
} from "@/api/user.js";
import viewPopup from "@/components/viewPopup.vue"
import goodPopup from "@/components/goodPopup.vue"
@@ -630,6 +631,10 @@
userInfoApi().then(res => {
const user = res.data;
userStore.setUserInfo(user);
+ if (!user.openid) loginUpdateUserApi({
+ mobile: user.mobile
+ })
+
if (user.is_staff == 1) {
uni.reLaunch({
url: "/multipleShop/verificationOrder/index"
diff --git a/pages/login/test.vue b/pages/login/test.vue
index 32c2ed4..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,
@@ -97,6 +98,9 @@
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..351e715 100644
--- a/pages/my/my.vue
+++ b/pages/my/my.vue
@@ -43,20 +43,20 @@
-
+
{{userInfo.now_money||"0.00"}}
余额
-
+
{{userInfo.purchase_funds||'0.00'}}
采购款
-
+
{{userInfo.return_money||'0.00'}}
返还金
-
+
{{userInfo.integral ||"0.00"}}
礼品券
From 1e52c22acda00c884ec19a8d6208f2fe0006b494 Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Mon, 24 Jun 2024 15:27:45 +0800
Subject: [PATCH 04/27] add
---
pageQuota/balanceDetail/index.vue | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/pageQuota/balanceDetail/index.vue b/pageQuota/balanceDetail/index.vue
index 47c6ca0..8a098ad 100644
--- a/pageQuota/balanceDetail/index.vue
+++ b/pageQuota/balanceDetail/index.vue
@@ -1,18 +1,17 @@
- {{mark}}
-
+
- 余额宝自动转入
- -204.00
+ {{item.title}}
+ {{item.amount}}
- 2024-10-21
- 余额 204.00
+ {{item.create_time}}
+ 余额 {{item.before_balance}}
@@ -46,11 +45,24 @@
const mark = ref(0)
const tabsChange = (e) => {
mark.value = e.index
+ getLists()
+ }
+
+
+ const lists = ref([])
+ let type = ''
+ const getLists = async () => {
+ let res = await getFundList({
+ type,
+ mark: mark.value || ''
+ })
+ lists.value = res.data.lists
}
onLoad((opt) => {
- console.log(opt)
+ type = opt.type
+ getLists()
})
From ea9e6ae292190b359a4865bb39f4f3b38567a545 Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Mon, 24 Jun 2024 16:51:25 +0800
Subject: [PATCH 05/27] add
---
pageQuota/balanceDetail/index.vue | 75 ++-
pages/my/my.vue | 10 -
utils/push.js | 751 ++++++++++++++++++++++++++++++
3 files changed, 809 insertions(+), 27 deletions(-)
create mode 100644 utils/push.js
diff --git a/pageQuota/balanceDetail/index.vue b/pageQuota/balanceDetail/index.vue
index 8a098ad..a38036c 100644
--- a/pageQuota/balanceDetail/index.vue
+++ b/pageQuota/balanceDetail/index.vue
@@ -3,17 +3,49 @@
-
-
-
- {{item.title}}
- {{item.amount}}
-
-
- {{item.create_time}}
- 余额 {{item.before_balance}}
+
+
+
+
+ {{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}}
+
+
+
+
+
+
+
+
@@ -24,13 +56,14 @@
reactive
} from "vue"
import {
- onLoad
+ onLoad,
+ onPullDownRefresh
} from "@dcloudio/uni-app"
import {
getFundList
} from "@/api/address.js"
-
+ const navLists = ['', '采购款明细', '余额明细', '礼品券明细', '返还金明细']
const tabsLst = reactive([{
name: '全部'
},
@@ -50,20 +83,28 @@
const lists = ref([])
- let type = ''
- const getLists = async () => {
+ let type = ref('')
+ const getLists = async (isPullDown = false) => {
let res = await getFundList({
- type,
+ type: type.value,
mark: mark.value || ''
})
lists.value = res.data.lists
+ if (isPullDown) uni.stopPullDownRefresh()
+
}
-
onLoad((opt) => {
- type = opt.type
+ type.value = opt.type
+ uni.setNavigationBarTitle({
+ title: navLists[type.value]
+ })
getLists()
})
+
+ onPullDownRefresh(() => {
+ getLists(true)
+ })
-
-
+
@@ -198,7 +198,7 @@
overflow: hidden;
position: relative;
width: 750rpx;
- height: 350rpx;
+ height: 250rpx;
.bg {
width: 100%;
@@ -212,7 +212,7 @@
box-sizing: border-box;
padding: 50rpx 0 50rpx 50rpx;
position: absolute;
- top: 150rpx;
+ top: 50rpx;
left: 0;
z-index: 2;
display: flex;
diff --git a/utils/push.js b/utils/push.js
index 78271ad..877fee4 100644
--- a/utils/push.js
+++ b/utils/push.js
@@ -1,751 +1,871 @@
-
-
-export const Push = 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();
+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);
+ 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.channel = function(name) {
+ return this.channels.find(name);
};
-Push.prototype.allChannels = function () {
- return this.channels.all();
+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;
- }
+Push.prototype.createConnection = function() {
+ if (this.connection) {
+ throw Error('Connection already exist');
+ }
+ var _this = this;
+ var url = this.config.url;
- params = JSON.parse(params.data);
- var event = params.event;
- var channel_name = params.channel;
+ 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;
+ }
- 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();
- }
- });
+ 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.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.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.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.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.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 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 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);
+function createPresenceChannel(channel_name, push) {
+ return createPrivateChannel(channel_name, push);
}
-/*window.addEventListener('online', function(){
- var con;
- for (var i in Push.instances) {
- con = Push.instances[i].connection;
- con.reconnectInterval = 1;
- if (con.state === 'connecting') {
- con.connect();
- }
- }
-});*/
-
+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();
+ 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.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.state === 'connected') {
- console.log('networkState is "' + this.state + '" and do not need connect');
- return;
- }
- if (this.reconnectTimer) {
- clearTimeout(this.reconnectTimer);
- this.reconnectTimer = 0;
- }
+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();
+ this.closeAndClean();
- var options = this.options;
- var websocket = new WebSocket(options.url+'/app/'+options.app_key);
+ 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);
+ }
+ });
- this.updateNetworkState('connecting');
+ if (options.onMessage) {
+ uni.onSocketMessage(options.onMessage);
+ }
- var _this = this;
- websocket.onopen = function (res) {
- _this.reconnectInterval = 1;
- if (_this.doNotConnect) {
- _this.updateNetworkState('disconnected');
- websocket.close();
- return;
- }
- if (options.onOpen) {
- options.onOpen(res);
- }
- };
+ uni.onSocketClose(function(res) {
+ _this.updateNetworkState('disconnected');
+ if (!_this.doNotConnect) {
+ _this.waitReconnect();
+ }
+ if (options.onClose) {
+ options.onClose(res);
+ }
+ });
- if (options.onMessage) {
- websocket.onmessage = options.onMessage;
- }
+ 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() {
- websocket.onclose = function (res) {
- websocket.onmessage = websocket.onopen = websocket.onclose = websocket.onerror = null;
- _this.updateNetworkState('disconnected');
- if (!_this.doNotConnect) {
- _this.waitReconnect();
- }
- if (options.onClose) {
- options.onClose(res);
- }
- };
-
- websocket.onerror = function (res) {
- _this.close();
- if (!_this.doNotConnect) {
- _this.waitReconnect();
- }
- if (options.onError) {
- options.onError(res);
- }
- };
- this.connection = websocket;
+ }
+ });
+ cb();
}
-Connection.prototype.closeAndClean = function () {
- if(this.connection) {
- var websocket = this.connection;
- websocket.onmessage = websocket.onopen = websocket.onclose = websocket.onerror = null;
- try {
- websocket.close();
- } catch (e) {}
- this.updateNetworkState('disconnected');
- }
+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.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;
- }
- this.connection.send(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');
- this.connection.close();
+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 __());
+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]];
- }
+ 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.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.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();
+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;
- }
+var Collections = (function() {
+ var exports = {};
- 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(" : ");
- }
+ 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.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.extend = extend;
- exports.arrayIndexOf = arrayIndexOf;
- function objectApply(object, f) {
- for (var key in object) {
- if (Object.prototype.hasOwnProperty.call(object, key)) {
- f(object[key], key, object);
- }
- }
- }
+ 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.objectApply = objectApply;
- function keys(object) {
- var keys = [];
- objectApply(object, function (_, key) {
- keys.push(key);
- });
- return keys;
- }
+ exports.stringify = stringify;
- exports.keys = keys;
- function values(object) {
- var values = [];
- objectApply(object, function (value) {
- values.push(value);
- });
- return values;
- }
+ 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.values = values;
- function apply(array, f, context) {
- for (var i = 0; i < array.length; i++) {
- f.call(context || (window), array[i], i, array);
- }
- }
+ exports.arrayIndexOf = arrayIndexOf;
- 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;
- }
+ function objectApply(object, f) {
+ for (var key in object) {
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
+ f(object[key], key, object);
+ }
+ }
+ }
- exports.map = map;
- function mapObject(object, f) {
- var result = {};
- objectApply(object, function (value, key) {
- result[key] = f(value);
- });
- return result;
- }
+ exports.objectApply = objectApply;
- 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;
- }
+ function keys(object) {
+ var keys = [];
+ objectApply(object, function(_, key) {
+ keys.push(key);
+ });
+ return keys;
+ }
- 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.keys = keys;
- exports.filterObject = filterObject;
- function flatten(object) {
- var result = [];
- objectApply(object, function (value, key) {
- result.push([key, value]);
- });
- return result;
- }
+ function values(object) {
+ var values = [];
+ objectApply(object, function(value) {
+ values.push(value);
+ });
+ return values;
+ }
- 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.values = values;
- 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;
- }
+ function apply(array, f, context) {
+ for (var i = 0; i < array.length; i++) {
+ f.call(context || (window), array[i], i, array);
+ }
+ }
- 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.apply = apply;
- 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("&");
- }
+ 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.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.map = map;
- exports.decycleObject = decycleObject;
- function safeJSONStringify(source) {
- try {
- return JSON.stringify(source);
- }
- catch (e) {
- return JSON.stringify(decycleObject(source));
- }
- }
+ function mapObject(object, f) {
+ var result = {};
+ objectApply(object, function(value, key) {
+ result[key] = f(value);
+ });
+ return result;
+ }
- exports.safeJSONStringify = safeJSONStringify;
- return exports;
+ 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 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;
+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;
+ return "_" + name;
}
-function __ajax(options){
- options=options||{};
- options.type=(options.type||'GET').toUpperCase();
- options.dataType=options.dataType||'json';
- params=formatParams(options.data);
+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');
- }
+ 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);
- }
- }
- }
+ 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);
- }
+ 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('&');
+function formatParams(data) {
+ var arr = [];
+ for (var name in data) {
+ arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
+ }
+ return arr.join('&');
}
-// export const push = {
-// a:6
-// }
\ No newline at end of file
+export default Push
\ No newline at end of file
From 002937f5a24bdc1056e3358bc351132492f4f7e7 Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Tue, 25 Jun 2024 13:44:10 +0800
Subject: [PATCH 08/27] add
---
config/app.js | 1 +
pageQuota/vipUser/index.vue | 24 +++--------------
pages/cart/cart.vue | 49 +++++++++++++++++------------------
pages/index/index.vue | 51 +++++++++++++++++--------------------
4 files changed, 51 insertions(+), 74 deletions(-)
diff --git a/config/app.js b/config/app.js
index e71ad8f..877f933 100644
--- a/config/app.js
+++ b/config/app.js
@@ -10,6 +10,7 @@ switch (env) {
case 'dev':
BASE_URL = 'https://test-multi-store.lihaink.cn';
WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
+ // WSS_URL = 'ws://192.168.1.22:8787'
break;
case 'liu':
BASE_URL = 'http://192.168.1.201:8545';
diff --git a/pageQuota/vipUser/index.vue b/pageQuota/vipUser/index.vue
index 224f94f..d052115 100644
--- a/pageQuota/vipUser/index.vue
+++ b/pageQuota/vipUser/index.vue
@@ -214,7 +214,7 @@
});
// 浏览器监听user-1
- const user_channel = connection.subscribe(`wechat_mmp_${userInfo.id}}`);
+ const user_channel = connection.subscribe(`wechat_mmp_${userInfo.id}`);
user_channel.on('message', function(data) {
console.log("收到消息--", data);
@@ -425,6 +425,9 @@
const submit = async () => {
if (!formData.real_name) return uni.$u.toast('请填写真实姓名');
if (!formData.mobile) return uni.$u.toast('请填写电话号码');
+ uni.showLoading({
+ title: '支付中...'
+ });
formData.store_id = STORE_INFO.id
if (Role.value == 1) {
uni.scanCode({
@@ -433,29 +436,10 @@
formData.recharge_type = 'INDUSTRYMEMBERS'
formData.user_ship = 1
vipRechargeApi(formData).then(res => {
- uni.showLoading({
- title: '支付中...'
- });
timer = setTimeout(() => {
uni.hideLoading();
uni.$u.toast('支付超时');
- // formData.real_name = ''
- // formData.mobile = ''
- // formData.address = ''
- // formData.label_name = ''
- // formData.city = ''
- // formData.area = ''
- // formData.street = ''
- // formData.village = ''
- // formData.brigade = ''
- // currentAddressIndex.value = 0
- // tabsList.forEach(item => {
- // item.name = '请选择'
- // })
}, 30000)
-
- // uni.$u.toast('操作成功');
-
})
getCount()
getLists()
diff --git a/pages/cart/cart.vue b/pages/cart/cart.vue
index 13f6a8b..01e0222 100644
--- a/pages/cart/cart.vue
+++ b/pages/cart/cart.vue
@@ -109,14 +109,11 @@
-
-
+
+
去结算({{checkAll}})
-
- ¥500起订
-
+
@@ -206,22 +203,22 @@
// 购物车相关
const addCart = (id, cart_num) => { //加入购物车
- if (uni.getStorageSync('STORE_INFO').length) {
- let data = JSON.parse(uni.getStorageSync('STORE_INFO'))
- let STORE_INFO = {};
- for (let key in data) {
- STORE_INFO[key] = data[key]
- }
- cartCreateApi({
- cart_num: +cart_num,
- product_id: id,
- store_id: STORE_INFO.id
- // store_id:
- }).then(res => {
- getcartList();
- })
- }
-
+ if (uni.getStorageSync('STORE_INFO').length) {
+ let data = JSON.parse(uni.getStorageSync('STORE_INFO'))
+ let STORE_INFO = {};
+ for (let key in data) {
+ STORE_INFO[key] = data[key]
+ }
+ cartCreateApi({
+ cart_num: +cart_num,
+ product_id: id,
+ store_id: STORE_INFO.id
+ // store_id:
+ }).then(res => {
+ getcartList();
+ })
+ }
+
}
const isAdmin = ref(false); //是否管理
@@ -253,10 +250,10 @@
} else {
checkAll.value = 0
}
- res.data.lists = res.data.lists.map(item => {
- if(!item.price) item.price = item.sell; // 兼容旧数据,新数据已经添加了price字段
- return item;
- })
+ res.data.lists = res.data.lists.map(item => {
+ if (!item.price) item.price = item.sell; // 兼容旧数据,新数据已经添加了price字段
+ return item;
+ })
cartList.value = res.data.lists;
cartInfo.value = {
total_price: res.data?.extend.total_price || '0.00',
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 749cef2..d247609 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -148,26 +148,24 @@
{{ item.store_name }}
-
- {{ item.spec }}
+
+
+
+
+ 活动价: ¥ {{ 66.65}}
+
+ /{{ item.unit_name }}
-
- 起批量: {{ item.batch }}{{ item.unit_name }}起卖
+
+ 原价: {{ item.store_name }}
+
+
+ 规格: {{ item.price }}/{{ item.unit_name }}
-
-
- ¥{{ item.price }}/{{ item.unit_name }}
+ 起批量: {{ item.batch }}{{ item.unit_name }}起卖
@@ -185,19 +183,14 @@
合计
¥{{ cartInfo.total_price }}
- ¥{{ cartInfo.total_price }}
- 优惠后
- {{ cartInfo.pay_price }}
-
+
+ {{cartInfo.msg }}
+
-
- {{ cartInfo.total_price < 500 ? "¥500起订" : "结算" }}
+ 结算
@@ -557,7 +550,8 @@
const cartInfo = ref({
total_price: '0.00',
pay_price: 0,
- count: 0
+ count: 0,
+ msg: ''
})
const getCartList = (res) => {
cartListApi({
@@ -567,6 +561,7 @@
cartInfo.value = {
total_price: res.data?.extend?.total_price || '0.00',
pay_price: res.data?.extend?.pay_price || '0.00',
+ msg: res.data?.extend?.msg || '',
count: res.data?.count || 0
}
cartStore.setCartList(res.data?.lists.map(item => item.id))
@@ -980,8 +975,8 @@
display: flex;
.shop-img {
- height: 120rpx;
- width: 120rpx;
+ height: 164rpx;
+ width: 164rpx;
margin-right: 20rpx;
border-radius: 14rpx;
overflow: hidden;
From e5d13a791f907dd2db5e77798d8a7a509ae41de9 Mon Sep 17 00:00:00 2001
From: zmj <1493694146@qq.com>
Date: Tue, 25 Jun 2024 15:34:24 +0800
Subject: [PATCH 09/27] add
---
api/user.js | 4 +
components/goodPopup.vue | 4 +-
pageQuota/vipUser/index.vue | 168 +++++++++++++++++-----------
pages/login/login.vue | 4 +-
pagesOrder/setPayPassword/index.vue | 5 +-
pagesOrder/settle/settle.vue | 153 +++++++++++++++----------
6 files changed, 213 insertions(+), 125 deletions(-)
diff --git a/api/user.js b/api/user.js
index 4e9c57d..c0d94dd 100644
--- a/api/user.js
+++ b/api/user.js
@@ -141,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..6736a34 100644
--- a/components/goodPopup.vue
+++ b/components/goodPopup.vue
@@ -28,14 +28,14 @@
¥ {{ subtotal }}
-
+
购买重量*
-
+
购买数量*
+
+
+
+
+
+ 重新获取({{cutDown}})
+ {{flag?'获取验证码':'重新获取' }}
+
+
+
@@ -67,8 +80,6 @@
-
{{Role==1?'完成并收款':'完成'}}
@@ -193,7 +204,8 @@
getStoreByPhone,
getUserLabel,
getUserShip,
- getCreateLists
+ getCreateLists,
+ getReportingSms
} from "@/api/user.js"
import Push from "@/utils/push.js"
import {
@@ -204,51 +216,6 @@
config
} from "@/config/app.js"
-
- // scoket
- let timer = null
- const userInfo = useUserStore().userInfo;
- const connection = new Push({
- url: config.WSS_URL, // websocket地址
- app_key: '2ce3ce22329517213caa7dad261f5695',
- });
-
- // 浏览器监听user-1
- const user_channel = connection.subscribe(`wechat_mmp_${userInfo.id}`);
-
- user_channel.on('message', function(data) {
- console.log("收到消息--", data);
- try {
- if (timer) clearTimeout(timer);
- uni.hideLoading()
- currentTab.value = 2
- formData.real_name = ''
- formData.mobile = ''
- formData.address = ''
- formData.label_name = ''
- formData.city = ''
- formData.area = ''
- formData.street = ''
- formData.village = ''
- formData.brigade = ''
- currentAddressIndex.value = 0
- tabsList.forEach(item => {
- item.name = '请选择'
- })
- getLists()
- getCount()
-
- } catch (error) {
-
- }
- });
- // 断线事件
- user_channel.on('close', function() {
-
- });
- // scoket结束
-
-
const showPop1 = ref(false)
const Role = ref('')
const range = ref({})
@@ -266,15 +233,14 @@
}).catch(err => {
uni.$u.toast('未查到店铺信息,请检查手机号码')
})
-
}
-
// 用户选择的门店信息
let STORE_INFO = reactive({
id: ""
})
+ // 门店手机号保留一天
const setPhoneOneDay = () => {
if (uni.getStorageSync('VIP_PHONE')) return;
const currentDate = new Date();
@@ -285,7 +251,6 @@
phone: storePhone.value
}));
}
-
const getPhoneOneDay = () => {
if (uni.getStorageSync('VIP_PHONE')) {
let data = JSON.parse(uni.getStorageSync('VIP_PHONE'))
@@ -296,25 +261,48 @@
}
}
}
+ // 手机保留一天结束
+ // 验证码
+ const cutDown = ref(0)
+ const flag = ref(true)
+ const code = ref('')
+ const checkPhone = (phone) => {
+ const regex = /^1[3-9]\d{9}$/;
+ return regex.test(formData.mobile) ? true : false
+ }
+ const getCode = async () => {
+ if (!checkPhone(formData.mobile)) return uni.$u.toast('请输入正确的手机号')
+ await getReportingSms({
+ account: formData.mobile
+ })
+ flag.value = false
+ cutDown.value = 60
+ let timer = setInterval(() => {
+ cutDown.value--
+ if (cutDown.value <= 0) clearInterval(timer)
+ }, 1000)
+ }
+ // 验证码结束
const currentTab = ref(1)
const formData = reactive({
store_id: STORE_INFO.id,
- mobile: "",
+ mobile: "19130550023",
province: 510000,
city: '',
area: "",
street: "",
village: "",
brigade: "",
- real_name: "",
+ real_name: "赵明军",
auth_code: "",
address: "",
label_name: "",
label_id: "",
- user_ship: ''
+ user_ship: '',
+ code: '8888'
})
const conformRole = (e) => {
@@ -337,7 +325,6 @@
const addressTbasChange = (e) => {
currentAddressIndex.value = e.index
}
-
const addressList = reactive({
city: [],
area: [],
@@ -345,7 +332,6 @@
village: [],
brigade: []
})
-
const addressLiClick = async (i, item) => {
if (i == 0) {
formData.city = item.city_code
@@ -392,7 +378,6 @@
.name
return currentAddressIndex.value++
}
-
const getCityList = async () => {
let res = await cityListApi({
province_code: formData.province
@@ -422,9 +407,30 @@
},
]);
+
+
+ // 支付相关
+ // scoket
+ let timer = null
+ const userInfo = useUserStore().userInfo;
+ const connection = new Push({
+ url: config.WSS_URL, // websocket地址
+ app_key: '2ce3ce22329517213caa7dad261f5695',
+ });
+
+ // 浏览器监听user-1
+ const user_channel = connection.subscribe(`wechat_mmp_${userInfo.id}`);
+ user_channel.on('message', function(data) {
+ console.log("收到消息--", data);
+ try {
+ if (timer) clearTimeout(timer);
+ paySuccessToTabs2()
+ } catch (error) {}
+ });
const submit = async () => {
if (!formData.real_name) return uni.$u.toast('请填写真实姓名');
if (!formData.mobile) return uni.$u.toast('请填写电话号码');
+ if (!formData.code) return uni.$u.toast('请输入短信验证码');
uni.showLoading({
title: '支付中...'
});
@@ -469,26 +475,53 @@
getCount()
})
}
-
}
-
const rePay = (item) => {
uni.scanCode({
success: function(res) {
+ uni.showLoading({
+ title: '支付中...'
+ });
reVipRechargeApi({
id: item.id,
auth_code: res.result
}).then(res => {
- uni.$u.toast('操作成功');
- getCount()
- getLists()
+ timer = setTimeout(() => {
+ uni.hideLoading();
+ uni.$u.toast('支付超时');
+ }, 30000)
})
}
});
-
}
+ // 支付成功后清除formData并且切换tabs2
+ const paySuccessToTabs2 = () => {
+ uni.hideLoading()
+ uni.showToast({
+ title: '支付成功',
+ duration: 2000,
+ success() {
+ currentTab.value = 2
+ formData.real_name = ''
+ formData.mobile = ''
+ formData.address = ''
+ formData.label_name = ''
+ formData.city = ''
+ formData.area = ''
+ formData.street = ''
+ formData.village = ''
+ formData.brigade = ''
+ currentAddressIndex.value = 0
+ tabsList.forEach(item => {
+ item.name = '请选择'
+ })
+ getLists()
+ getCount()
+ }
+ });
+ }
// 邀请用户数
const count = ref(0)
@@ -687,4 +720,13 @@
.slot-content {
padding-bottom: 50rpx;
}
+
+ .code-btn {
+ display: flex;
+ align-items: center;
+ }
+
+ .btn-text {
+ color: #20B128;
+ }
\ No newline at end of file
diff --git a/pages/login/login.vue b/pages/login/login.vue
index d497af0..de72004 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);
diff --git a/pagesOrder/setPayPassword/index.vue b/pagesOrder/setPayPassword/index.vue
index c113ac9..7cbcee1 100644
--- a/pagesOrder/setPayPassword/index.vue
+++ b/pagesOrder/setPayPassword/index.vue
@@ -85,10 +85,12 @@
form.password.length < 6 ?
form.password += e :
showKeyBorad.value = false
+ if (form.password.length == 6) showKeyBorad.value = false;
} else {
form.rePassword.length < 6 ?
form.rePassword += e :
showKeyBorad.value = false
+ if (form.rePassword.length == 6) showKeyBorad.value = false;
}
}
@@ -102,10 +104,9 @@
// 键盘事件结束
-
-
const submit = async () => {
if (!form.code) return uni.$u.toast('请输入验证码');
+ if (form.password.length < 6) return uni.$u.toast('请输入6位数密码');
if (form.password !== form.rePassword) return uni.$u.toast('两次密码不一致');
await setPayPassword({
...form
diff --git a/pagesOrder/settle/settle.vue b/pagesOrder/settle/settle.vue
index 4dc095a..d82ee71 100644
--- a/pagesOrder/settle/settle.vue
+++ b/pagesOrder/settle/settle.vue
@@ -77,50 +77,6 @@
-
- 支付方式
-
-
-
- 微信支付
-
-
-
-
-
-
-
-
-
-
-
- 余额支付
- ( 可用¥{{userInfo.now_money}}
- )
-
-
-
-
-
-
-
-
-
-
- 采购款支付
- ( 可用¥{{userInfo.purchase_funds}}
- )
-
-
-
-
-
-
-