123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //引入公共方法
- const dever = require('./dever/core.js');
- App({
- /**
- * 保存邀请人id
- */
- saveInviteUid(uid){
- dever.save('invite_uid', uid);
- },
- /**
- * 获取邀请人id
- */
- getInviteUid(){
- let inviteUid = dever.getSave('invite_uid')
- return inviteUid == null ? '': inviteUid;
- },
- /**
- * 判断是否登录状态
- */
- isLogin: function (){
- return dever.getSign() == '' ? false : true;
- },
- /**
- * 判断是否授权
- */
- isAuth: function(scope, fun){
- wx.getSetting({
- withCredentials: true,
- success(res) {
- if (res.authSetting[scope]) {
- fun(true);
- } else {
- fun(false)
- }
- }
- })
- },
- /**
- * 获取用户id
- */
- getUid: function(){
- return dever.getUid();
- },
- getLoginInfo: function(){
- return dever.getLoginInfo();
- },
- /**
- * 设置模板变量[单个]
- */
- set: function (self, key, value) {
- var data = {};
- data[key] = value;
- this.sets(self, data);
- },
- /**
- * 设置模板变量[多个]
- */
- sets: function (self, data) {
- self.setData(data);
- },
- /**
- * 设置模板变量[列表]
- */
- setList: function (self, value, isAppend) {
- if (isAppend) {
- let list = self.data.list;
- for (var i = 0; i < value.length; i++) {
- list.push(value[i]);
- }
- this.set(self, 'list', list);
- } else {
- this.set(self, 'list', value);
- }
- },
- /**
- * 获取模板里传过来的data
- */
- getData: function (event) {
- return event.currentTarget.dataset;
- },
- /**
- * Toast提示框 3s消失
- */
- toast: function (msg, title) {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 3000
- });
- },
- /**
- * 解析html
- */
- html: function (bindName, data, target) {
- var wxParse = dever.package('wxParse/wxParse');
- wxParse.wxParse(bindName, 'html', data, target, 0);
- },
- /**
- * 跳转页面
- */
- location: function (url) {
- dever.log('location', url);
- wx.navigateTo({
- url: '../../template/' + url,
- })
- },
- /**
- * 重定向页面
- */
- redirect: function (url) {
- dever.log('redirect', url);
- wx.redirectTo({
- url: '../../template/' + url,
- })
- },
- /**
- * 回退 delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页
- */
- goBack: function (delta) {
- if (typeof delta != 'number') delta = 1;
- wx.navigateBack({
- delta: delta
- })
- },
- /**
- * 开始下拉刷新
- */
- startPullDown: function (self) {
- wx.showNavigationBarLoading();
- self.onLoad();
- },
- /**
- * 停止下拉刷新
- */
- stopPullDown: function () {
- wx.hideNavigationBarLoading();
- wx.stopPullDownRefresh();
- },
- /**
- * 显示加载中[数据交互动画]
- */
- showLoading: function () {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- },
- /**
- * 隐藏加载中
- */
- hideLoading: function () {
- wx.hideLoading();
- },
- /**
- * http请求
- * url 请求路径
- * param 请求参数 {}
- * callback 回调方法 {success fail complete}
- * method 请求方式 OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- */
- request: function (url, param, callback, method){
- if (!param) param = {};
-
- //是否返回json格式的数据1为返回2为不返回
- param['json'] = 1;
-
- //用于登录后的uid验证,每次都要传入
- param['signature'] = dever.getSign();
- var that = this;
- console.log(url, param);
- dever.package('network').request(dever, url, param, {
- success: function(res){
- if (res.data.status == 1) {
- let data = res.data.data;
- if (data.config) {
- dever.setSetting(data.config);
- }
- if (url == 'passport.applet.bind'){
- dever.saveLoginInfo(data);
- }
- callback.success(data, res);
- } else {
- callback.fail(res);
- }
- },
- fail: function(res){
- callback.fail(res);
- },
- complete: function(res){
- if(callback.complete){
- callback.complete(res);
- }
- that.stopPullDown();
- dever.log('request ' + url, res);
- }
- }, method);
- }
- })
|