react - build a service -2

export const DEFAULT_TITLE = "hello";

// export const PRODUCT_SERVER_URL = "http://10.10.1.12:8080/lottery/api";
// export const DEV_SERVER_URL = "http://10.10.1.12:8080/lottery/api";

//缓存信息
export const CACHE_LOTTERY = "cache_lottery";
export const CACHE_LOTTERY_TYPE = CACHE_LOTTERY+"_type";
export const CACHE_LOTTERY_HISTORY = CACHE_LOTTERY+"_history";
export const CACHE_LOTTERY_HISTORY_DETAIL = CACHE_LOTTERY+"_history_detail";

export const CACHE_USER = "cache_user";
export const CACHE_USER_ORDER = CACHE_USER+"_order";

export const CACHE_LOTTERY_SELECTED_NUM = CACHE_LOTTERY + "_selected_num";

// lottery has not timed button prompt
export const BUY_INFO_BTN = "not timed";
// limit the amount of lottery
Export const BUY_LIMIT_MONEY = 20000;
// bind bank card limit on the number
Export const BANK_CARD_LIMIT = 5;
Export = const PAGE_FIRST_INFO "we have the latest data";
Export PAGE_LAST_INFO = const "is the last one";
Export const PAPER_FIRST = "current is the latest one";
Export const PAPER_LAST = "current is the last one";

// Interface returned successfully encoded
Export const SUCCESS = "0000";
// whether APP base debug mode false
Export const APP_MODE = false;
Export const APP_LOCAL_MODE = false;

// is currently in development environment
Export function isDevEnv () {
the let the env = process.env;
IF (env.NODE_ENV == 'dev') {
return to true;
} the else {
return to false;
}
}

// development, online context switch URL
Export function urlTransmit (URL) {
the let the env = process.env;
IF (env.NODE_ENV == 'dev') {
return URL DEV_SERVER_URL +;
} the else {
return URL PRODUCT_SERVER_URL +;
}
}

// continue to buffer data for later
Export function continueBuyInfo (NUM) {
var numInfo;
IF (cacheExists (CACHE_LOTTERY_SELECTED_NUM)) {
numInfo = cacheGet (CACHE_LOTTERY_SELECTED_NUM);
} the else {
numInfo = [];
}
numInfo.push (NUM);
CacheSet (CACHE_LOTTERY_SELECTED_NUM , numInfo);
}

// delete the cache data continues later
Export function continueBuyInfoDelete (NUM) {
var numInfo;
IF (cacheExists (CACHE_LOTTERY_SELECTED_NUM)) {
numInfo = cacheGet (CACHE_LOTTERY_SELECTED_NUM);
} the else {
numInfo = [];
}
arrayDel (numInfo, NUM);
CacheSet ( CACHE_LOTTERY_SELECTED_NUM, numInfo);
}

// plurality of later
Export function multiBuyDialog (JSON) {
h5app.multiBuyDialog (the JSON.stringify (JSON));
}

// top page
Export function Finish () {
IF (APP_MODE) {
h5app.finish ();
} the else {
console.log ( "Finish ...");
}
}

// alert message
Export function Toast (MSG) {
IF (APP_MODE) {
h5app.showToast (MSG);
} the else {
Alert (MSG);
}
}

//开启Loading
export function openLoading(){
if(APP_MODE){
h5app.dialog(true);
// toast("loading open...");
}else{
console.log("loading open...");
}
}

//关闭Loading
export function closeLoading(){
if(APP_MODE){
h5app.dialog(false);
// toast("loading close...");
}else{
console.log("loading close...");
}
}

//注数计算
export function lottery_cal(lotteryType, playType, joinNum){
if(APP_MODE){
return h5app.lottery_cal(lotteryType, playType, joinNum);
}else{
return 1;
}
}

// set-top box ID
Export tvBoxNum function () {
IF (APP_MODE) {
return h5app.deviceId ();
} the else {
return "1212121212";
}
}

//tvToken
export function tvToken(){
var userinfo = this.userinfo();
var tvToken = "";
if(userinfo && userinfo.tvToken){
tvToken = userinfo.tvToken;
}
return tvToken;
}

//是否登录
export function isLogin(){
if(APP_MODE){
if(APP_LOCAL_MODE){
return true;
}else{
var userinfo = h5app.getUserInfoJson();
if(userinfo){
return true;
}else{
return false;
}
}
}else{
return true;
}
}

// login page
Export gotoLogin function () {
IF (APP_MODE) {
h5app.go2LoginView ();
} the else {
Toast ( "go to the login page")
}
}

//用户信息
export function userinfo(){
var info = {
"userToken": "ZWVhYWE2M2IxYWM4NGU4N2IwZWRjMzQzNTYxOWVlYjN8MTI0MTMyNTE1fHVzZXI=",
"balance": "4215611.00",
"phone": "13554296038",
"tvToken": "YzU4YTA3NzcwY2YzNGI4OGI1YzVjZTc5MjM5OTNmZDh8MTI0MTMyNTE1fHR2",
"name": "胡",
"identityCard": "420111111111111111",
"userId": "124132515",
"account": "13554296038"
};

if(APP_MODE){
    if(APP_LOCAL_MODE){
        return info;
    }else{
        var userinfo = h5app.getUserInfoJson();
        if(userinfo){
            return JSON.parse(userinfo);
        }else{
            return {};
        }
    }
}else{
    return info;
}

}

//选择的号码拆分
export function selectBallSplit(num){
var arr = [];
var arr1 = num.split("|");
var showFlag = true;
var twoFlag = false;
if(num.indexOf("-") != -1){
twoFlag = true;
}
for(var i=0; i<arr1.length; i++){
if(arr1[i]){
var arrTemp = [];
var temp = [];
if(twoFlag){
temp = arr1[i].split("-");
}else{
temp = arr1[i].split("");
}

        for(var j=0; j<temp.length; j++){
            arrTemp.push(temp[j]);
        }
        
        if(temp.length > 1 && !showFlag){
            arr.push(["|"]);
        }
        arr.push(arrTemp);
        if(temp.length > 1){
            arr.push(["|"]);
            showFlag = true;
        }else{
            showFlag = false;
        }
    }
}

//删除最后一个竖线
if(arr.length > 0 && arr[arr.length-1].length == 1 && arr[arr.length-1][0] == "|"){
    arr.splice(arr.length-1, 1);
}
return arr;

}

//号码拆分
export function ballSplit(num){
var ballList = [];
var splitFlag = false;
if(num){
ballList = num.split("|");
if(ballList[0].indexOf("-") != -1){
splitFlag = true;
}
}

var redList = [];
var blueList = [];
if(ballList.length >= 1){
    var red = ballList[0];
    var blue = "";
    if(ballList.length == 2){
        blue = ballList[1];
    }

    //红球蓝球拆分
    if(splitFlag){
        redList = red.split("-");
    }else{
        redList = red.split("");
    }

    if(blue){
        if(splitFlag){
            blueList = blue.split("-");
        }else{
            blueList = blue.split("");
        }
    }
}

return {
    redList: redList,
    blueList: blueList
};

}

//隐藏银行卡号部分内容
export function hideCardNum(num){
var newNum = "";
var numArr = [];
if(num){
numArr = num.split("")
}
if(numArr.length > 8){
for(var i=0; i<numArr.length; i++){
if(i < 4 || i >= 8){
newNum += numArr[i];
}else{
newNum += "*";
}
}
}
return newNum;
}

//隐藏电话号码部分内容
export function hidePhoneNum(num){
var newNum = "";
var numArr = [];
if(num){
numArr = num.split("")
}
if(numArr.length > 7){
for(var i=0; i<numArr.length; i++){
if(i < 3 || i >= 7){
newNum += numArr[i];
}else{
newNum += "*";
}
}
}
return newNum;
}

//隐藏身份证号部分内容
export function hideIdNum(num){
var newNum = "";
var numArr = [];
if(num){
numArr = num.split("")
}
if(numArr.length >= 15){
for(var i=0; i<numArr.length; i++){
if(i < 6 || i >= 14){
newNum += numArr[i];
}else{
newNum += "*";
}
}
}
return newNum;
}

//彩种信息
export function lotteryInfo(lotteryType){
var lotteryName = "";
var lotteryNameImg = "";
if(lotteryType == "100"){
lotteryName = "大乐透";
lotteryNameImg = "assets/img/logo/dlt.png";
}else if(lotteryType == "101"){
lotteryName = "排列三";
lotteryNameImg = "assets/img/logo/pls.png";
}else if(lotteryType == "102"){
lotteryName = "排列五";
lotteryNameImg = "assets/img/logo/plw.png";
}else if(lotteryType == "103"){
lotteryName = "七星彩";
lotteryNameImg = "assets/img/logo/qxc.png";
}else if(lotteryType == "104"){
lotteryName = "胜负彩";
lotteryNameImg = "assets/img/logo/sfc.png";
}else if(lotteryType == "105"){
lotteryName = "任选九";
lotteryNameImg = "assets/img/logo/rxj.png";
}else if(lotteryType == "106"){
lotteryName = "进球彩";
lotteryNameImg = "assets/img/logo/jqc.png";
}else if(lotteryType == "107"){
lotteryName = "半全场";
lotteryNameImg = "assets/img/logo/bqc.png";
}else if(lotteryType == "200"){
lotteryName = "双色球";
lotteryNameImg = "assets/img/logo/ssball.png";
}else if(lotteryType == "201"){
lotteryName = "七乐彩";
lotteryNameImg = "assets/img/logo/qlc.png";
}else if(lotteryType == "202"){
lotteryName = "福彩3D";
lotteryNameImg = "assets/img/logo/3d.png";
}
return {
lotteryName: lotteryName,
lotteryNameImg: lotteryNameImg
}
}

Every second day for the second conversion //
Export function secondsFormat (S) {
IF (S) {
var Day Math.floor = (S / (24 3600)); // Math.floor () rounded down
var hour = Math .floor ((S - Day
24 3600) / 3600);
var Math.floor minute = ((S - Day
24 3600 - hour 3600) / 60);
var = S SECOND - Day 24 3600 - hour 3600 - minute 60;
return day + "day" ++ "when the" hour + minute + "points" SECOND + + "seconds";
} the else {
return S;
}
}

// intercept the address bar parameter
export function getQueryString (param) {// param is to get the name of the parameter Note: get is not null
var CURRENTURL = window.location.href; // Get the current link
var arr = currentUrl.split ( "?"); // segmentation and parameter limit domain
IF (arr.length>. 1) {
ARR ARR = [. 1] .split ( "&"); // segmentation parameters
for (var i = 0; i <arr .length; I ++) {
var TEM ARR = [I] .split ( "="); // parameter name and content divided
IF (TEM [0] == param) {
return TEM [. 1];
}
}
return null;
}
the else {
return null;
}
}

// thousandth
Export function the format (NUM) {
IF (NUM) {
NUM = the parseInt (NUM) + ''; // digitizer string
var str = ""; // string accumulated
for (var i = num . 1 .length-, J =. 1; I> = 0; I -, J ++) {
! IF (J == 0 &&. 3% I = 0) {// every three comma, the first filter just digit case
str + [i] = num + ","; // add thousandths comma
Continue;
}
STR + = [I] NUM; // accumulated digital backwards
}
return str.split ( '') Reverse (. ) .join ( ""); // string => array => reverse => string
} the else {
return NUM;
}
}

// n is a positive number to verify the
Export function validateNum (NUM) {
var /^\d+(?=.{0,1}\d+$|$)/ REG =
IF (reg.test (NUM)) return to true;
to false return;
}

export function cacheExists(name){
let cacheData = sessionStorage.getItem(name);
if(cacheData){
return true;
}else{
return false;
}
}
export function cacheClear(name){
return sessionStorage.clear();
}
export function cacheRemove(name){
return sessionStorage.removeItem(name);
}
export function cacheGet(name){
return JSON.parse(sessionStorage.getItem(name));
}
export function cacheSet(name, data){
sessionStorage.setItem(name, JSON.stringify(data));
}

Guess you like

Origin www.cnblogs.com/pp-air/p/12084149.html