123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- "use strict";
- var common_vendor = require("../common/vendor.js");
- var api_user = require("../api/user.js");
- function isEmpty(obj) {
- if (obj == "undefined" || obj == null || obj == "") {
- return true;
- } else {
- return false;
- }
- }
- function isLogin() {
- return new Promise((resolve, reject) => {
- api_user.checkLogin().then((res) => {
- if (res.code == 200) {
- resolve(true);
- } else {
- resolve(false);
- }
- }, (rej) => {
- });
- });
- }
- function isLoginCourse() {
- return new Promise((resolve, reject) => {
- let token = common_vendor.index.getStorageSync("AppTokenmini_RTCourse");
- if (token == null || token == void 0 || token == "") {
- resolve(false);
- } else {
- resolve(true);
- }
- });
- }
- function getDictLabelName(dicts, dictValue) {
- if (dictValue == null) {
- return "";
- }
- var name = "";
- dicts.forEach(function(item, index, array) {
- if (dictValue.toString() == item.dictValue.toString()) {
- name = item.dictLabel;
- }
- });
- return name;
- }
- function parseText(txt, len) {
- if (txt.length > len) {
- var text = txt.substr(0, len) + "...";
- return text;
- }
- return txt;
- }
- function parseIDCardInfo(idCard) {
- var reg = /^\d{17}[\dXx]$/;
- if (reg.test(idCard)) {
- var birthday = idCard.substring(6, 14);
- var year = birthday.substring(0, 4);
- var month = birthday.substring(4, 6);
- var day = birthday.substring(6, 8);
- var currentYear = new Date().getFullYear();
- var age = currentYear - parseInt(year);
- var genderCode = parseInt(idCard.charAt(16));
- var gender = genderCode % 2 === 0 ? "\u5973" : "\u7537";
- return {
- birthday: year + "-" + month + "-" + day,
- age,
- gender
- };
- }
- return null;
- }
- function getProvider(service) {
- return new Promise((resolve, reject) => {
- common_vendor.index.getProvider({
- service: service || "oauth",
- success: function(res) {
- if (res.provider) {
- resolve(res.provider[0]);
- }
- },
- fail() {
- reject("\u83B7\u53D6\u73AF\u5883\u670D\u52A1\u5546\u5931\u8D25");
- }
- });
- }).catch((error) => {
- console.log("167", error);
- });
- }
- function parsePhone(mobile) {
- console.log(mobile);
- if (mobile != null) {
- var str = mobile.substr(0, 3) + "****" + mobile.substr(7);
- return str;
- }
- }
- function getAge(strBirthday) {
- var returnAge, strBirthdayArr = strBirthday.split("-"), birthYear = strBirthdayArr[0], birthMonth = strBirthdayArr[1], birthDay = strBirthdayArr[2], d = new Date(), nowYear = d.getFullYear(), nowMonth = d.getMonth() + 1, nowDay = d.getDate();
- if (nowYear == birthYear) {
- returnAge = 0;
- } else {
- var ageDiff = nowYear - birthYear;
- if (ageDiff > 0) {
- if (nowMonth == birthMonth) {
- var dayDiff = nowDay - birthDay;
- if (dayDiff < 0) {
- returnAge = ageDiff - 1;
- } else {
- returnAge = ageDiff;
- }
- } else {
- var monthDiff = nowMonth - birthMonth;
- if (monthDiff < 0) {
- returnAge = ageDiff - 1;
- } else {
- returnAge = ageDiff;
- }
- }
- } else {
- returnAge = -1;
- }
- }
- return returnAge;
- }
- function parseIdCard(idCard) {
- var str = idCard.substr(0, 4) + "****" + idCard.substr(8);
- return str;
- }
- function urlToObj(url) {
- let obj = {};
- let str = url.slice(url.indexOf("?") + 1);
- let arr = str.split("&");
- for (let j = arr.length, i = 0; i < j; i++) {
- let arr_temp = arr[i].split("=");
- obj[arr_temp[0]] = arr_temp[1];
- }
- return obj;
- }
- function logout() {
- common_vendor.index.setStorageSync("AppToken", null);
- }
- function clearHisSearch() {
- var searchList = [];
- common_vendor.index.setStorageSync("hisSearch", JSON.stringify(searchList));
- }
- function getHisSearch() {
- var search = common_vendor.index.getStorageSync("hisSearch");
- if (search != null && search != void 0 && search != "") {
- var search = JSON.parse(search);
- return search;
- } else {
- var data = [];
- return data;
- }
- }
- function addHisSearch(searchVal) {
- var search = common_vendor.index.getStorageSync("hisSearch");
- var searchList = [];
- console.log(searchList);
- if (search != null && search != void 0 && search != "") {
- searchList = JSON.parse(search);
- }
- searchList.push(searchVal);
- const uniqueArr = [...new Set(searchList)];
- common_vendor.index.setStorageSync("hisSearch", JSON.stringify(uniqueArr));
- }
- function generateRandomString(length) {
- let result = "";
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- const charactersLength = characters.length;
- for (let i = 0; i < length; i++) {
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
- }
- return result;
- }
- exports.addHisSearch = addHisSearch;
- exports.clearHisSearch = clearHisSearch;
- exports.generateRandomString = generateRandomString;
- exports.getAge = getAge;
- exports.getDictLabelName = getDictLabelName;
- exports.getHisSearch = getHisSearch;
- exports.getProvider = getProvider;
- exports.isEmpty = isEmpty;
- exports.isLogin = isLogin;
- exports.isLoginCourse = isLoginCourse;
- exports.logout = logout;
- exports.parseIDCardInfo = parseIDCardInfo;
- exports.parseIdCard = parseIdCard;
- exports.parsePhone = parsePhone;
- exports.parseText = parseText;
- exports.urlToObj = urlToObj;
|