This commit is contained in:
zmj 2024-06-24 18:40:03 +08:00
parent b8aaa100b4
commit 6605fe5571
7 changed files with 905 additions and 696 deletions

View File

@ -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);
}

View File

@ -1,4 +1,5 @@
let BASE_URL
let WSS_URL
import store from "@/store/user.js"
// 环境
let env = "dev"
@ -8,12 +9,15 @@ let env = "dev"
switch (env) {
case 'dev':
BASE_URL = 'https://test-multi-store.lihaink.cn';
WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
break;
case 'liu':
BASE_URL = 'http://192.168.1.201:8545';
WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
break;
default:
BASE_URL = 'https://multi-store.lihaink.cn';
WSS_URL = 'wss://test-multi-store.lihaink.cn/pull'
}
let HTTP_REQUEST_URL
@ -21,6 +25,7 @@ let HEADER
let config = {
HTTP_REQUEST_URL: BASE_URL,
WSS_URL: WSS_URL,
HEADER: {
'content-type': 'application/json',
//#ifdef MP

View File

@ -21,8 +21,8 @@
<view class="li" v-for="(item,index) in lists" :key="index">
<view class="li-top">
<text>{{item.title}}</text>
<text style="font-weight: bold;" :style="{color:item.financial_pm?'#50C758':'red'
}">{{ item.financial_pm?'+':'-' }}{{item.number}}</text>
<text style="font-weight: bold;" :style="{color:!item.financial_pm?'#50C758':'red'
}">{{ !item.financial_pm?'+':'-' }}{{item.number}}</text>
</view>
<view class="li-top" style="margin-bottom: 0;">
<text style="font-size: 24rpx;color: grey;">{{item.create_time}}</text>
@ -33,8 +33,8 @@
<view class="li" v-for="(item,index) in lists" :key="index">
<view class="li-top">
<text>{{item.order_sn}}</text>
<text style="font-weight: bold;" :style="{color:item.status?'#50C758':'red'
}">{{ item.status?'+':'-' }}{{item.number}}</text>
<text style="font-weight: bold;" :style="{color:!item.status?'#50C758':'red'
}">{{ !item.status?'+':'-' }}{{item.number}}</text>
</view>
<view class="li-top" style="margin-bottom: 0;">
<text style="font-size: 24rpx;color: grey;">{{item.create_time}}</text>
@ -68,10 +68,10 @@
name: '全部'
},
{
name: '支出'
name: '收入'
},
{
name: '收入'
name: '支出'
},
]);
@ -81,7 +81,6 @@
getLists()
}
const lists = ref([])
let type = ref('')
const getLists = async (isPullDown = false) => {

View File

@ -28,19 +28,19 @@
{{Role==1?'行业会员':'商户'}}开通报备
</view>
<up-form labelPosition="left" :model="formData" :borderBottom='false'>
<up-form-item label="" prop="userInfo.name">
<up-form-item label="">
<up-input v-model="formData.real_name" border="none" prefixIcon="account" placeholder="请输入真实姓名"
:customStyle="{background:'#F3F3F3',padding:'20rpx','border-radius':'30rpx'}"
:placeholderStyle="{color:'#444444'}"
:prefixIconStyle="{'margin-right':'40rpx'}"></up-input>
</up-form-item>
<up-form-item label="" prop="userInfo.name">
<up-form-item label="">
<up-input v-model="formData.mobile" border="none" prefixIcon="phone" placeholder="请输入电话号码"
:customStyle="{background:'#F3F3F3',padding:'20rpx','border-radius':'30rpx'}"
:placeholderStyle="{color:'#444444'}"
:prefixIconStyle="{'margin-right':'40rpx'}"></up-input>
</up-form-item>
<up-form-item label="" prop="userInfo.name">
<up-form-item label="">
<view @click="showPop=true" style="width: 100%;">
<up-input style="pointer-events: none" v-model="formData.address" border="none"
prefixIcon="map" readonly placeholder="点击选择地址" :customStyle="{background:'#F3F3F3',padding:'20rpx',
@ -50,7 +50,7 @@
</view>
</up-form-item>
<up-form-item label="" prop="userInfo.name" v-if='Role==1'>
<up-form-item label="" v-if='Role==1'>
<view @click="showPop1=true" style="width: 100%;">
<up-input style="pointer-events: none" v-model="formData.label_name" border="none"
prefixIcon="man-add" readonly placeholder="点击选择用户身份" :customStyle="{background:'#F3F3F3',padding:'20rpx',
@ -107,15 +107,21 @@
<uni-td style="font-size: 20rpx;" align="center" v-if='Role==1'>{{item.label_name}}</uni-td>
<uni-td style="font-size: 20rpx;" align="center">
<view v-if="item.paid ==1 ||Role==4">已开通</view>
<view v-else @click="upadtaStatus(item)" style="color:#33B83A ;">未开通,查询</view>
<view v-else style="color:#33B83A ;">
<view @click="upadtaStatus(item)">
未开通,查询
</view>
<view @click="rePay(item)">
重新支付
</view>
</view>
</uni-td>
</uni-tr>
</uni-table>
</view>
</block>
</view>
<view style="height: 50rpx;" />
<!-- 地址选择器 -->
<up-popup :show="showPop" @close="showPop=false" @open="showPop=true" :round="10">
@ -169,6 +175,7 @@
reactive,
ref
} from 'vue';
import useUserStore from "@/store/user";
import {
provinceListApi,
cityListApi,
@ -180,6 +187,7 @@
import {
vipRechargeApi,
rechargeCountApi,
reVipRechargeApi,
rechargeListsApi,
updataOrderApi,
getStoreByPhone,
@ -187,11 +195,59 @@
getUserShip,
getCreateLists
} from "@/api/user.js"
import Push from "@/utils/push.js"
import {
onPullDownRefresh,
onLoad
} from "@dcloudio/uni-app"
import {
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('')
@ -377,22 +433,28 @@
formData.recharge_type = 'INDUSTRYMEMBERS'
formData.user_ship = 1
vipRechargeApi(formData).then(res => {
uni.$u.toast('操作成功');
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
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)
tabsList.forEach(item => {
item.name = '请选择'
})
// uni.$u.toast('');
})
getCount()
@ -426,6 +488,24 @@
}
const rePay = (item) => {
uni.scanCode({
success: function(res) {
reVipRechargeApi({
id: item.id,
auth_code: res.result
}).then(res => {
uni.$u.toast('操作成功');
getCount()
getLists()
})
}
});
}
//
const count = ref(0)
const getCount = async () => {
@ -451,7 +531,6 @@
})
lists.value = res.data.lists
count.value = res.data.count
}
}
@ -464,13 +543,15 @@
updataOrderApi({
order_no: item.order_id,
recharge: 1
}).then(res => {
getCount()
getLists()
})
}
onLoad(() => {
getUserShip().then(res => {
console.log(res)
range.value = res.data.lists.map(item => {
return {
value: item.id,

View File

@ -53,7 +53,7 @@
"style": {
"navigationBarTitleText": "个人中心",
"enablePullDownRefresh": true,
"navigationStyle": "custom"
"navigationBarBackgroundColor": "#D3FDCA"
}
}, {
"path": "pages/charge/charge_record",

View File

@ -23,8 +23,8 @@
</style>
<template>
<view>
<up-navbar title="我的" :autoBack="true" bgColor="transparent" :fixed="true">
</up-navbar>
<!-- <up-navbar title="我的" :autoBack="true" bgColor="transparent" :fixed="true">
</up-navbar> -->
<view class="user-info">
<image class="bg" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/e3a7b202404261113002322.webp"
mode="widthFix"></image>
@ -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;

View File

@ -1,6 +1,4 @@
export const Push = function Push(options) {
function Push(options) {
this.doNotConnect = 0;
options = options || {};
options.heartbeat = options.heartbeat || 25000;
@ -17,7 +15,7 @@ export const Push = function Push(options) {
Push.prototype.checkoutPing = function() {
var _this = this;
_this.checkoutPingTimer && clearTimeout(_this.checkoutPingTimer);
_this.checkoutPingTimer = setTimeout(function () {
_this.checkoutPingTimer = setTimeout(function() {
_this.checkoutPingTimer = 0;
if (_this.connection.state === 'connected') {
_this.connection.send('{"event":"pusher:ping","data":{}}');
@ -25,7 +23,7 @@ Push.prototype.checkoutPing = function() {
clearTimeout(_this.pingTimeoutTimer);
_this.pingTimeoutTimer = 0;
}
_this.pingTimeoutTimer = setTimeout(function () {
_this.pingTimeoutTimer = setTimeout(function() {
_this.connection.closeAndClean();
if (!_this.connection.doNotConnect) {
_this.connection.waitReconnect();
@ -35,19 +33,20 @@ Push.prototype.checkoutPing = function() {
}, this.config.heartbeat);
};
Push.prototype.channel = function (name) {
Push.prototype.channel = function(name) {
return this.channels.find(name);
};
Push.prototype.allChannels = function () {
Push.prototype.allChannels = function() {
return this.channels.all();
};
Push.prototype.createConnection = function () {
Push.prototype.createConnection = function() {
if (this.connection) {
throw Error('Connection already exist');
}
var _this = this;
var url = this.config.url;
function updateSubscribed () {
function updateSubscribed() {
for (var i in _this.channels) {
_this.channels[i].subscribed = false;
}
@ -55,12 +54,12 @@ Push.prototype.createConnection = function () {
this.connection = new Connection({
url: url,
app_key: this.config.app_key,
onOpen: function () {
_this.connection.state ='connecting';
onOpen: function() {
_this.connection.state = 'connecting';
_this.checkoutPing();
},
onMessage: function(params) {
if(_this.pingTimeoutTimer) {
if (_this.pingTimeoutTimer) {
clearTimeout(_this.pingTimeoutTimer);
_this.pingTimeoutTimer = 0;
}
@ -76,7 +75,8 @@ Push.prototype.createConnection = function () {
if (event === 'pusher:error') {
throw Error(params.data.message);
}
var data = JSON.parse(params.data), channel;
var data = JSON.parse(params.data),
channel;
if (event === 'pusher_internal:subscription_succeeded') {
channel = _this.channels[channel_name];
channel.subscribed = true;
@ -90,7 +90,7 @@ Push.prototype.createConnection = function () {
_this.subscribeAll();
}
if (event.indexOf('pusher_internal') !== -1) {
console.log("Event '"+event+"' not implement");
console.log("Event '" + event + "' not implement");
return;
}
channel = _this.channels[channel_name];
@ -98,20 +98,20 @@ Push.prototype.createConnection = function () {
channel.emit(event, data);
}
},
onClose: function () {
onClose: function() {
updateSubscribed();
},
onError: function () {
onError: function() {
updateSubscribed();
}
});
};
Push.prototype.disconnect = function () {
Push.prototype.disconnect = function() {
this.connection.doNotConnect = 1;
this.connection.close();
};
Push.prototype.subscribeAll = function () {
Push.prototype.subscribeAll = function() {
if (this.connection.state !== 'connected') {
return;
}
@ -121,15 +121,20 @@ Push.prototype.subscribeAll = function () {
}
};
Push.prototype.unsubscribe = function (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}}));
this.connection.send(JSON.stringify({
event: "pusher:unsubscribe",
data: {
channel: channel_name
}
}));
}
}
};
Push.prototype.unsubscribeAll = function () {
Push.prototype.unsubscribeAll = function() {
var channels = Object.keys(this.channels);
if (channels.length) {
if (this.connection.state === 'connected') {
@ -140,7 +145,7 @@ Push.prototype.unsubscribeAll = function () {
}
this.channels = {};
};
Push.prototype.subscribe = function (channel_name) {
Push.prototype.subscribe = function(channel_name) {
if (this.channels[channel_name]) {
return this.channels[channel_name];
}
@ -154,32 +159,41 @@ Push.prototype.subscribe = function (channel_name) {
};
Push.instances = [];
function createChannel(channel_name, push)
{
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.subscribeCb = function() {
push.connection.send(JSON.stringify({
event: "pusher:subscribe",
data: {
channel: channel_name
}
}));
}
channel.processSubscribe();
return channel;
}
function createPrivateChannel(channel_name, push)
{
function createPrivateChannel(channel_name, push) {
var channel = new Channel(push.connection, channel_name);
push.channels[channel_name] = channel;
channel.subscribeCb = function () {
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: {
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}));
push.connection.send(JSON.stringify({
event: "pusher:subscribe",
data: data
}));
},
error: function (e) {
error: function(e) {
throw Error(e);
}
});
@ -188,13 +202,12 @@ function createPrivateChannel(channel_name, push)
return channel;
}
function createPresenceChannel(channel_name, push)
{
function createPresenceChannel(channel_name, push) {
return createPrivateChannel(channel_name, push);
}
/*window.addEventListener('online', function(){
var con;
uni.onNetworkStatusChange(function(res) {
if (res.isConnected) {
for (var i in Push.instances) {
con = Push.instances[i].connection;
con.reconnectInterval = 1;
@ -202,8 +215,8 @@ function createPresenceChannel(channel_name, push)
con.connect();
}
}
});*/
}
});
function Connection(options) {
this.dispatcher = new Dispatcher();
@ -221,15 +234,87 @@ function Connection(options) {
this.connect();
}
Connection.prototype.updateNetworkState = function(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 });
this.emit('state_change', {
previous: old_state,
current: state
});
}
};
Connection.prototype.connect = function () {
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');
@ -243,29 +328,28 @@ Connection.prototype.connect = function () {
this.closeAndClean();
var options = this.options;
var websocket = new WebSocket(options.url+'/app/'+options.app_key);
this.updateNetworkState('connecting');
var _this = this;
websocket.onopen = function (res) {
var cb = function() {
uni.onSocketOpen(function(res) {
_this.reconnectInterval = 1;
if (_this.doNotConnect) {
_this.updateNetworkState('disconnected');
websocket.close();
uni.closeSocket();
return;
}
if (options.onOpen) {
options.onOpen(res);
}
};
});
if (options.onMessage) {
websocket.onmessage = options.onMessage;
uni.onSocketMessage(options.onMessage);
}
websocket.onclose = function (res) {
websocket.onmessage = websocket.onopen = websocket.onclose = websocket.onerror = null;
uni.onSocketClose(function(res) {
_this.updateNetworkState('disconnected');
if (!_this.doNotConnect) {
_this.waitReconnect();
@ -273,9 +357,9 @@ Connection.prototype.connect = function () {
if (options.onClose) {
options.onClose(res);
}
};
});
websocket.onerror = function (res) {
uni.onSocketError(function(res) {
_this.close();
if (!_this.doNotConnect) {
_this.waitReconnect();
@ -283,22 +367,31 @@ Connection.prototype.connect = function () {
if (options.onError) {
options.onError(res);
}
});
};
this.connection = websocket;
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.connection) {
var websocket = this.connection;
websocket.onmessage = websocket.onopen = websocket.onclose = websocket.onerror = null;
try {
websocket.close();
} catch (e) {}
this.updateNetworkState('disconnected');
Connection.prototype.closeAndClean = function() {
if (this.state === 'connected') {
uni.closeSocket();
}
this.updateNetworkState('disconnected');
};
Connection.prototype.waitReconnect = function () {
Connection.prototype.waitReconnect = function() {
if (this.state === 'connected' || this.state === 'connecting') {
return;
}
@ -308,7 +401,7 @@ Connection.prototype.waitReconnect = function () {
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
}
this.reconnectTimer = setTimeout(function(){
this.reconnectTimer = setTimeout(function() {
_this.connect();
}, this.reconnectInterval);
if (this.reconnectInterval < 1000) {
@ -329,17 +422,25 @@ Connection.prototype.send = function(data) {
console.trace('networkState is "' + this.state + '", can not send ' + data);
return;
}
this.connection.send(data);
uni.sendSocketMessage({
data: data
});
}
Connection.prototype.close = function(){
Connection.prototype.close = function() {
this.updateNetworkState('disconnected');
this.connection.close();
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; }
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 __());
};
@ -357,14 +458,14 @@ function Channel(connection, channel_name) {
}
}
Channel.prototype.processSubscribe = function () {
Channel.prototype.processSubscribe = function() {
if (this.connection.state !== 'connected') {
return;
}
this.subscribeCb();
};
Channel.prototype.processQueue = function () {
Channel.prototype.processQueue = function() {
if (this.connection.state !== 'connected' || !this.subscribed) {
return;
}
@ -374,20 +475,25 @@ Channel.prototype.processQueue = function () {
this.queue = [];
};
Channel.prototype.trigger = function (event, data) {
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.queue.push(function() {
_this.connection.send(JSON.stringify({
event: event,
data: data,
channel: _this.channelName
}));
});
this.processQueue();
};
////////////////
var Collections = (function () {
var Collections = (function() {
var exports = {};
function extend(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
@ -399,8 +505,7 @@ var Collections = (function () {
if (extensions[property] && extensions[property].constructor &&
extensions[property].constructor === Object) {
target[property] = extend(target[property] || {}, extensions[property]);
}
else {
} else {
target[property] = extensions[property];
}
}
@ -409,13 +514,13 @@ var Collections = (function () {
}
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 {
} else {
m.push(safeJSONStringify(arguments[i]));
}
}
@ -423,6 +528,7 @@ var Collections = (function () {
}
exports.stringify = stringify;
function arrayIndexOf(array, item) {
var nativeIndexOf = Array.prototype.indexOf;
if (array === null) {
@ -440,6 +546,7 @@ var Collections = (function () {
}
exports.arrayIndexOf = arrayIndexOf;
function objectApply(object, f) {
for (var key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
@ -449,24 +556,27 @@ var Collections = (function () {
}
exports.objectApply = objectApply;
function keys(object) {
var keys = [];
objectApply(object, function (_, key) {
objectApply(object, function(_, key) {
keys.push(key);
});
return keys;
}
exports.keys = keys;
function values(object) {
var values = [];
objectApply(object, function (value) {
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);
@ -474,6 +584,7 @@ var Collections = (function () {
}
exports.apply = apply;
function map(array, f) {
var result = [];
for (var i = 0; i < array.length; i++) {
@ -483,17 +594,19 @@ var Collections = (function () {
}
exports.map = map;
function mapObject(object, f) {
var result = {};
objectApply(object, function (value, key) {
objectApply(object, function(value, key) {
result[key] = f(value);
});
return result;
}
exports.mapObject = mapObject;
function filter(array, test) {
test = test || function (value) {
test = test || function(value) {
return !!value;
};
var result = [];
@ -506,9 +619,10 @@ var Collections = (function () {
}
exports.filter = filter;
function filterObject(object, test) {
var result = {};
objectApply(object, function (value, key) {
objectApply(object, function(value, key) {
if ((test && test(value, key, object, result)) || Boolean(value)) {
result[key] = value;
}
@ -517,15 +631,17 @@ var Collections = (function () {
}
exports.filterObject = filterObject;
function flatten(object) {
var result = [];
objectApply(object, function (value, key) {
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)) {
@ -536,6 +652,7 @@ var Collections = (function () {
}
exports.any = any;
function all(array, test) {
for (var i = 0; i < array.length; i++) {
if (!test(array[i], i, array)) {
@ -546,8 +663,9 @@ var Collections = (function () {
}
exports.all = all;
function encodeParamsObject(data) {
return mapObject(data, function (value) {
return mapObject(data, function(value) {
if (typeof value === "object") {
value = safeJSONStringify(value);
}
@ -556,16 +674,19 @@ var Collections = (function () {
}
exports.encodeParamsObject = encodeParamsObject;
function buildQueryString(data) {
var params = filterObject(data, function (value) {
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 = [];
var objects = [],
paths = [];
return (function derez(value, path) {
var i, name, nu;
switch (typeof value) {
@ -575,7 +696,9 @@ var Collections = (function () {
}
for (i = 0; i < objects.length; i += 1) {
if (objects[i] === value) {
return {$ref: paths[i]};
return {
$ref: paths[i]
};
}
}
objects.push(value);
@ -585,8 +708,7 @@ var Collections = (function () {
for (i = 0; i < value.length; i += 1) {
nu[i] = derez(value[i], path + '[' + i + ']');
}
}
else {
} else {
nu = {};
for (name in value) {
if (Object.prototype.hasOwnProperty.call(value, name)) {
@ -604,11 +726,11 @@ var Collections = (function () {
}
exports.decycleObject = decycleObject;
function safeJSONStringify(source) {
try {
return JSON.stringify(source);
}
catch (e) {
} catch (e) {
return JSON.stringify(decycleObject(source));
}
}
@ -617,25 +739,25 @@ var Collections = (function () {
return exports;
})();
var Dispatcher = (function () {
var Dispatcher = (function() {
function Dispatcher(failThrough) {
this.callbacks = new CallbackRegistry();
this.global_callbacks = [];
this.failThrough = failThrough;
}
Dispatcher.prototype.on = function (eventName, callback, context) {
Dispatcher.prototype.on = function(eventName, callback, context) {
this.callbacks.add(eventName, callback, context);
return this;
};
Dispatcher.prototype.on_global = function (callback) {
Dispatcher.prototype.on_global = function(callback) {
this.global_callbacks.push(callback);
return this;
};
Dispatcher.prototype.off = function (eventName, callback, context) {
Dispatcher.prototype.off = function(eventName, callback, context) {
this.callbacks.remove(eventName, callback, context);
return this;
};
Dispatcher.prototype.emit = function (eventName, data) {
Dispatcher.prototype.emit = function(eventName, data) {
var i;
for (i = 0; i < this.global_callbacks.length; i++) {
this.global_callbacks[i](eventName, data);
@ -645,8 +767,7 @@ var Dispatcher = (function () {
for (i = 0; i < callbacks.length; i++) {
callbacks[i].fn.call(callbacks[i].context || (window), data);
}
}
else if (this.failThrough) {
} else if (this.failThrough) {
this.failThrough(eventName, data);
}
return this;
@ -654,14 +775,14 @@ var Dispatcher = (function () {
return Dispatcher;
}());
var CallbackRegistry = (function () {
var CallbackRegistry = (function() {
function CallbackRegistry() {
this._callbacks = {};
}
CallbackRegistry.prototype.get = function (name) {
CallbackRegistry.prototype.get = function(name) {
return this._callbacks[prefix(name)];
};
CallbackRegistry.prototype.add = function (name, callback, context) {
CallbackRegistry.prototype.add = function(name, callback, context) {
var prefixedEventName = prefix(name);
this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
this._callbacks[prefixedEventName].push({
@ -669,7 +790,7 @@ var CallbackRegistry = (function () {
context: context
});
};
CallbackRegistry.prototype.remove = function (name, callback, context) {
CallbackRegistry.prototype.remove = function(name, callback, context) {
if (!name && !callback && !context) {
this._callbacks = {};
return;
@ -677,14 +798,14 @@ var CallbackRegistry = (function () {
var names = name ? [prefix(name)] : Collections.keys(this._callbacks);
if (callback || context) {
this.removeCallback(names, callback, context);
}
else {
} 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) {
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);
});
@ -693,59 +814,58 @@ var CallbackRegistry = (function () {
}
}, this);
};
CallbackRegistry.prototype.removeAllCallbacks = function (names) {
Collections.apply(names, function (name) {
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';
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');
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);
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);
} 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]));
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
// }
export default Push