Commit 30d16745 authored by haiyoucuv's avatar haiyoucuv

init

parent 1b5560fd
......@@ -2,7 +2,9 @@
// 获取应用实例
import { ComponentWithStore } from "mobx-miniprogram-bindings";
import { store } from "../../store/store";
import { dbLogin } from "../../utils/request";
import { dbLogin, request } from "../../utils/request";
import { API_PATH } from "../../utils/config";
import { _asyncThrottle } from "../../utils/util";
const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
......@@ -59,6 +61,15 @@ ComponentWithStore({
showPhoneBtn: !store.homeInfo.mobile,
});
},
clickSubscribe: _asyncThrottle(async function () {
console.log('clickSubscribe', this)
await request({
url: API_PATH.subscribe,
});
await this.updateHomeInfo();
}),
closeGetPanel() {
this.setData({
showGetPanel: false,
......
......@@ -14,7 +14,7 @@
</view>
<view class="content_info">
<view class="content_info_bg"></view>
<view class="content_sub">订阅消息</view>
<view class="content_sub" wx:if="{{!homeInfo.subscribe}}" bindtap="clickSubscribe">订阅消息</view>
<view class="content_act_list">
<view class="content_act_list_title">热门活动</view>
<view class="content_act_list_more">查看更多 ></view>
......
......@@ -17,3 +17,38 @@ const formatNumber = (n: number) => {
const s = n.toString()
return s[1] ? s : '0' + s
}
/**
* @description: 支持异步函数的节流,防止接口时间太长击穿防连点
* @return {Function}
* @param fun
* @param delay
*/
export const _asyncThrottle = (fun, delay = 2000) => {
let last, deferTimer;
let canClick = true;
return function () {
const now = Date.now();
if (!canClick) return;
if (last && now < last + delay) {
// clearTimeout(deferTimer);
// deferTimer = setTimeout(() => {
// last = now;
// }, delay);
} else {
last = now;
// @ts-ignore
const ps = fun.apply(this, arguments);
if (ps instanceof Promise) {
canClick = false;
ps.then(() => {
canClick = true;
});
}
}
};
};
......@@ -8,7 +8,7 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"noImplicitThis": true,
"noImplicitThis": false,
"noImplicitReturns": true,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment