123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import { showToast } from './utils/feedback'
- import { formatTime, arrRemoveObj,getTypeItem } from './utils/util'
- // const baseUrl = "https://test-ding.g107.com/";//测试
- const baseUrl = "https://ding.insys.g107.com/";//正式
- var that;
- App({
- //自定义全局变量
- globalData: {
- showToast: showToast,//提示框
- arrRemoveObj: arrRemoveObj,//删除数组的某一项
- year: formatTime(new Date()).year,//当前年
- month: formatTime(new Date()).month,//当前月
- day: formatTime(new Date()).day,//当前日
- types:[],
- userData: '',
- token:'',
- // token:' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90ZXN0LWRpbmcuZzEwNy5jb21cL2FwaVwvdGVzdCIsImlhdCI6MTU5Nzg4NjUyOSwiZXhwIjoxNTk4NDg2NTI5LCJuYmYiOjE1OTc4ODY1MjksImp0aSI6IktvRmR2bk1VVThaN2poWjkiLCJzdWIiOjEsInBydiI6ImNhNjQ4OWQ1MGYyNDA3YTY3ODMwZTgwOTBkMDE0ODgzNTY4NTk2MmIiLCJyb2xlIjoiZW1wbG95ZWUifQ.1gjqd9WgrK7N_ugz0ljIniScr8fCBucFzNJE3Cjo1sg',
- ALIOSS_URL: 'https://integralsys.oss-cn-shenzhen.aliyuncs.com',
- imgHttpUrl:'https://intesys.cms.g107.com/integral.php/Api/get_signature',
- corpId:'',
- },
- //获取积分类型
- getTypes() {
- this.$get("api/integral/types", {}).then((res) => {
- this.globalData.types = res.data.data.list;
- })
- },
- //封装post
- $post(url, data={}) {
- const promise = new Promise(function (resolve, reject) {
- dd.httpRequest({
- url: baseUrl + url,
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'A-Token': that.globalData.token
- },
- data: data,
- dataType: 'json',
- success: function (res) {
- if (res.data.code == 1) {
- if (res.refresh_token && res.data.refresh_token != that.globalData.token) {
- that.globalData.token = res.data.refresh_token
- }
- resolve(res);
- } else if (res.data.code == 401) {
- that.globalData.showToast("登录已过期");
- reject(res);
- } else {
- that.globalData.showToast(res.data.msg);
- reject(res);
- }
- },
- fail: function (res) {
- reject(res);
- }
- });
- })
- return promise;
- },
- //封装get
- $get(url,data={},Accept) {
- const promise = new Promise(function (resolve, reject) {
- dd.showLoading();
- dd.httpRequest({
- url: baseUrl + url,
- method: 'GET',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'A-Token': that.globalData.token,
- 'Accept': Accept ? Accept:''
- },
- data: data,
- dataType: 'json',
- success: function (res) {
- dd.hideLoading();
- if (res.data.code == 1) {
- if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
- that.globalData.token = res.data.refresh_token
- }
- resolve(res);
- } else if (res.data.code == 401) {
- that.globalData.showToast("登录已过期");
- // reject(res);
- } else {
- that.globalData.showToast(res.data.msg)
- // reject(res);
- }
- },
- fail: function (res) {
- dd.hideLoading();
- reject(res);
- },
- });
- })
- return promise;
- },
- //免登
- login(corpId, callBack) {
- dd.getAuthCode({
- success: function (res) {
- that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
- if (res.data.code == 1) {
- var { token, user } = res.data.data;
- if(user.is_official==1){
- that.globalData.token = token;
- that.globalData.userData = user;
- callBack();
- }else{
- dd.navigateTo({
- url:'./pages/workbench/noJurisdiction'
- })
- }
- } else {
- that.globalData.showToast(res.msg)
- }
- }).catch(err=>{
- console.log(err);
- })
- },
- fail:function(err){
- console.log(err)
- }
- });
- },
- getTypesItem(id){
- return getTypeItem(this.globalData.types,id);
- },
- onLaunch(options) {
- that = this;
- that.getTypes();
- that.globalData.corpId = options.query.corpId;
- },
- });
|