common.js 2.6 KB

1
  1. "use strict";var o=require("../common/vendor.js"),d=require("../api/user.js");function v(e){return e=="undefined"||e==null||e==""}function S(){return new Promise((e,r)=>{d.checkLogin().then(n=>{n.code==200?e(!0):e(!1)},n=>{})})}function p(){return new Promise((e,r)=>{let n=o.index.getStorageSync("AppTokenmini_RTCourse");n==null||n==null||n==""?e(!1):e(!0)})}function m(e,r){if(r==null)return"";var n="";return e.forEach(function(t,s,i){r.toString()==t.dictValue.toString()&&(n=t.dictLabel)}),n}function b(e,r){if(e.length>r){var n=e.substr(0,r)+"...";return n}return e}function y(e){var r=/^\d{17}[\dXx]$/;if(r.test(e)){var n=e.substring(6,14),t=n.substring(0,4),s=n.substring(4,6),i=n.substring(6,8),a=new Date().getFullYear(),c=a-parseInt(t),l=parseInt(e.charAt(16)),g=l%2===0?"\u5973":"\u7537";return{birthday:t+"-"+s+"-"+i,age:c,gender:g}}return null}function L(e){return new Promise((r,n)=>{o.index.getProvider({service:e||"oauth",success:function(t){t.provider&&r(t.provider[0])},fail(){n("\u83B7\u53D6\u73AF\u5883\u670D\u52A1\u5546\u5931\u8D25")}})}).catch(r=>{console.log("167",r)})}function x(e){if(console.log(e),e!=null){var r=e.substr(0,3)+"****"+e.substr(7);return r}}function w(e){var r,n=e.split("-"),t=n[0],s=n[1],i=n[2],a=new Date,c=a.getFullYear(),l=a.getMonth()+1,g=a.getDate();if(c==t)r=0;else{var u=c-t;if(u>0)if(l==s){var f=g-i;f<0?r=u-1:r=u}else{var h=l-s;h<0?r=u-1:r=u}else r=-1}return r}function A(e){var r=e.substr(0,4)+"****"+e.substr(8);return r}function I(e){let r={},t=e.slice(e.indexOf("?")+1).split("&");for(let s=t.length,i=0;i<s;i++){let a=t[i].split("=");r[a[0]]=a[1]}return r}function P(){o.index.setStorageSync("AppToken",null)}function j(){var e=[];o.index.setStorageSync("hisSearch",JSON.stringify(e))}function O(){var e=o.index.getStorageSync("hisSearch");if(e!=null&&e!=null&&e!=""){var e=JSON.parse(e);return e}else{var r=[];return r}}function T(e){var r=o.index.getStorageSync("hisSearch"),n=[];console.log(n),r!=null&&r!=null&&r!=""&&(n=JSON.parse(r)),n.push(e);const t=[...new Set(n)];o.index.setStorageSync("hisSearch",JSON.stringify(t))}function H(e){let r="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=n.length;for(let s=0;s<e;s++)r+=n.charAt(Math.floor(Math.random()*t));return r}exports.addHisSearch=T;exports.clearHisSearch=j;exports.generateRandomString=H;exports.getAge=w;exports.getDictLabelName=m;exports.getHisSearch=O;exports.getProvider=L;exports.isEmpty=v;exports.isLogin=S;exports.isLoginCourse=p;exports.logout=P;exports.parseIDCardInfo=y;exports.parseIdCard=A;exports.parsePhone=x;exports.parseText=b;exports.urlToObj=I;