common.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. import {checkLogin,logoutjpushId,getLastAndReadStatus,updateHistoryApp} from '@/api/user'
  2. import { getSopCourseStudyList } from "@/api/courseAnswer.js"
  3. import { bdCallBackReq } from '@/api/index.js'
  4. import { bindCompanyFsUser } from '@/api/companyUser.js'
  5. const TOKEN_KEY = 'AppToken'; // token 信息
  6. const CONFIG_KEY = 'QXT_MAGMT_CONFIG_KEY'; // 系统配置
  7. const USER_KEY = 'QXT_MAGMT_USER_KEY'; // 账号信息
  8. const SITE_BASE_URL_KEY = 'SITE_BASE_URL_KEY'; // 链接信息
  9. const SIP_ACCOUNT_KEY = 'SIP_ACCOUNT_KEY'; // 链接信息
  10. let idCode=null;
  11. let sdkwx = null;
  12. // #ifdef APP-PLUS
  13. idCode = uni.requireNativePlugin('Ba-IdCode');
  14. sdkwx = uni.requireNativePlugin('Wework-SdkWX'); // 企业微信登陆、分享插件
  15. // #endif
  16. // tabBar
  17. const tabBarPages = [
  18. // '/pages/index/index',
  19. '/pages/course/index',
  20. '/pages/course/video/living-app',
  21. '/pages/TUIKit/TUIPages/TUIConversation/index',
  22. '/pages_im/pages/conversation/conversationList/index',
  23. '/pages/user/index'
  24. ]
  25. function userDefaults(key) {
  26. let ret = '';
  27. ret = uni.getStorageSync(key);
  28. if (!ret) {
  29. ret = '{}';
  30. }
  31. let obj = JSON.parse(ret);
  32. return obj;
  33. }
  34. /**
  35. * 获取当前登录用户的令牌信息
  36. * @return {Object} 登录令牌信息
  37. */
  38. function getUserToken() {
  39. let usertoken = userDefaults(TOKEN_KEY);
  40. return usertoken;
  41. };
  42. /**
  43. * 添加当前登录用户的令牌信息
  44. * @param {Object} tokenInfo 令牌信息
  45. */
  46. function setUserToken(tokenInfo) {
  47. let tokens = getUserToken()
  48. let newToken = Object.assign(tokens, tokenInfo); // 只有在登陆是才能获取签名、实名状态,刷新token时只会返回token,不能直接得到状态,这里只调整覆盖原来的token
  49. uni.setStorageSync(TOKEN_KEY, JSON.stringify(newToken));
  50. };
  51. export function parseText(txt,len) {
  52. if(txt.length>len){
  53. var text=txt.substr(0,len)+"..."
  54. return text;
  55. }
  56. return txt;
  57. }
  58. export function parseIDCardInfo(idCard) {
  59. // 正则表达式匹配身份证号格式
  60. var reg = /^\d{17}[\dXx]$/;
  61. if (reg.test(idCard)) {
  62. // 提取出生日期
  63. var birthday = idCard.substring(6, 14);
  64. var year = birthday.substring(0, 4);
  65. var month = birthday.substring(4, 6);
  66. var day = birthday.substring(6, 8);
  67. // 计算年龄
  68. var currentYear = new Date().getFullYear();
  69. var age = currentYear - parseInt(year);
  70. // 提取性别
  71. var genderCode = parseInt(idCard.charAt(16));
  72. var gender = genderCode % 2 === 0 ? "女" : "男";
  73. return {
  74. birthday: year + "-" + month + "-" + day,
  75. age: age,
  76. gender: gender
  77. };
  78. }
  79. return null; // 身份证号格式不正确
  80. }
  81. export function isEmpty(obj) {
  82. if (obj == undefined || obj == null || obj=="") {
  83. return true;
  84. } else {
  85. return false;
  86. }
  87. }
  88. /**
  89. * 是否登录
  90. * @return {Boolean} true 登录 false 未登录
  91. */
  92. export function isLogin() {
  93. let obj=uni.getStorageSync(TOKEN_KEY);
  94. return !!obj;
  95. }
  96. export function logout() {
  97. const logoutAction=()=>{
  98. uni.setStorageSync(TOKEN_KEY,null);
  99. uni.removeStorageSync("userInfo");
  100. uni.removeStorageSync("onLaunch");
  101. uni.removeStorageSync("companyUser");
  102. uni.removeStorageSync("CompanyUserToken");
  103. uni.$emit("refreshUserInfo")
  104. uni.navigateTo({
  105. url: '/pages/auth/loginIndex'
  106. });
  107. //关闭推送事件监听
  108. uni.offPushMessage();
  109. plus.runtime.setBadgeNumber(0);
  110. };
  111. // #ifdef APP-PLUS
  112. logoutjpushId().then(res=>{
  113. if(res.code == 200){
  114. } else {
  115. uni.showToast({
  116. title: res.msg,
  117. icon: 'none'
  118. });
  119. }
  120. logoutAction();
  121. },
  122. rej => {
  123. logoutAction();
  124. }
  125. );
  126. // #endif
  127. // #ifndef APP-PLUS
  128. uni.setStorageSync(TOKEN_KEY,null);
  129. uni.removeStorageSync("companyUser");
  130. uni.removeStorageSync("CompanyUserToken");
  131. uni.removeStorageSync("onLaunch")
  132. uni.$emit("refreshUserInfo")
  133. uni.navigateTo({
  134. url: '/pages/auth/loginIndex'
  135. })
  136. // #endif
  137. }
  138. var toast=function(msg) {
  139. // #ifdef APP-PLUS
  140. uni.showToast({title: msg,icon: 'none',duration:2000,position:'bottom'});
  141. // #endif
  142. // #ifdef H5
  143. uni.showToast({ title: msg,icon: 'none',duration:2000});
  144. // #endif
  145. }
  146. export function getDictLabelName(dicts,dictValue) {
  147. if(dictValue==null){
  148. return "";
  149. }
  150. var name="";
  151. dicts.forEach(function(item, index, array) {
  152. if(dictValue.toString()==item.dictValue.toString()){
  153. name=item.dictLabel
  154. }
  155. });
  156. return name;
  157. }
  158. export function getStoreDictByName(key,dictValue) {
  159. if(dictValue==null || dictValue==-1){
  160. return "请选择";
  161. }
  162. var dicts = uni.getStorageSync(key);
  163. var dict=JSON.parse(dicts);
  164. var name="";
  165. dict.forEach(function(item, index, array) {
  166. if(dictValue.toString()==item.dictValue.toString()){
  167. name=item.dictLabel
  168. }
  169. });
  170. return name;
  171. }
  172. var getStoreIndexByName= function(key,dictValue) {
  173. if(dictValue==null || dictValue==-1){
  174. return [0];
  175. }
  176. var dicts = uni.getStorageSync(key);
  177. var dict=JSON.parse(dicts);
  178. var defIndexs=[0];
  179. dict.forEach(function(item, index, array) {
  180. if(dictValue.toString()==item.dictValue.toString()){
  181. defIndexs=[index];
  182. }
  183. });
  184. return defIndexs;
  185. }
  186. var getStorageByKey=function(key){
  187. let storageObj=uni.getStorageSync(key);
  188. var dataArr=[];
  189. if(!!storageObj){
  190. dataArr=JSON.parse(storageObj);
  191. }
  192. return dataArr;
  193. }
  194. var getStorageNamesByKey=function(key){
  195. let storageObj=uni.getStorageSync(key);
  196. if(!!storageObj){
  197. var tempArr=JSON.parse(storageObj);
  198. var valueArr=[];
  199. tempArr.forEach(function(item, index, array) {
  200. valueArr.push(item.dictLabel);
  201. });
  202. return valueArr;
  203. }
  204. }
  205. var getDict= function(key) {
  206. var dicts = uni.getStorageSync('dicts');
  207. dicts=JSON.parse(dicts);
  208. var dict=dicts[key]
  209. return dict;
  210. }
  211. var photosToArr= function(photoUrl) {
  212. var photos=[];
  213. if(photoUrl!=null&&photoUrl!=''){
  214. photos=photoUrl.split(',');
  215. }
  216. return photos
  217. }
  218. var dateFormat=function dateFormat(fmt, date) {
  219. let ret;
  220. const opt = {
  221. "Y+": date.getFullYear().toString(), // 年
  222. "m+": (date.getMonth() + 1).toString(), // 月
  223. "d+": date.getDate().toString(), // 日
  224. "H+": date.getHours().toString(), // 时
  225. "M+": date.getMinutes().toString(), // 分
  226. "S+": date.getSeconds().toString() // 秒
  227. // 有其他格式化字符需求可以继续添加,必须转化成字符串
  228. };
  229. for (let k in opt) {
  230. ret = new RegExp("(" + k + ")").exec(fmt);
  231. if (ret) {
  232. fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
  233. };
  234. };
  235. return fmt;
  236. }
  237. var getProvider = service => {
  238. return new Promise((resolve, reject) => {
  239. // 获取当前环境的服务商
  240. uni.getProvider({
  241. service: service || 'oauth',
  242. success: function (res) {
  243. // 此处可以排除h5
  244. if (res.provider) {
  245. resolve(res.provider[0])
  246. }
  247. },
  248. fail() {
  249. reject('获取环境服务商失败')
  250. },
  251. })
  252. }).catch(error => {
  253. console.log('167', error)
  254. })
  255. }
  256. export function parsePhone(mobile) {
  257. var str = mobile.substr(0,3)+"****"+mobile.substr(7);
  258. return str;
  259. }
  260. export function getAge(strBirthday){
  261. var returnAge,
  262. strBirthdayArr=strBirthday.split("-"),
  263. birthYear = strBirthdayArr[0],
  264. birthMonth = strBirthdayArr[1],
  265. birthDay = strBirthdayArr[2],
  266. d = new Date(),
  267. nowYear = d.getFullYear(),
  268. nowMonth = d.getMonth() + 1,
  269. nowDay = d.getDate();
  270. if(nowYear == birthYear){
  271. returnAge = 0;//同年 则为0周岁
  272. }
  273. else{
  274. var ageDiff = nowYear - birthYear ; //年之差
  275. if(ageDiff > 0){
  276. if(nowMonth == birthMonth) {
  277. var dayDiff = nowDay - birthDay;//日之差
  278. if(dayDiff < 0) {
  279. returnAge = ageDiff - 1;
  280. }else {
  281. returnAge = ageDiff;
  282. }
  283. }else {
  284. var monthDiff = nowMonth - birthMonth;//月之差
  285. if(monthDiff < 0) {
  286. returnAge = ageDiff - 1;
  287. }
  288. else {
  289. returnAge = ageDiff ;
  290. }
  291. }
  292. }else {
  293. returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
  294. }
  295. }
  296. return returnAge;//返回周岁年龄
  297. }
  298. const urlToObj = function(url) {
  299. let obj = {}
  300. let str = url.slice(url.indexOf('?') + 1)
  301. let arr = str.split('&')
  302. for (let j = arr.length, i = 0; i < j; i++) {
  303. let arr_temp = arr[i].split('=')
  304. obj[arr_temp[0]] = arr_temp[1]
  305. }
  306. return obj
  307. }
  308. /**
  309. * 判断是否为空对象
  310. * @param {Object} 时间字符串
  311. */
  312. var isNullObj=function(obj) {
  313. let isNull=(JSON.stringify(obj) == "{}");
  314. return isNull;
  315. }
  316. var arrContainsVal=function(arr,val){
  317. var isContains=false;
  318. for (var i = 0; i < arr.length; i++) {
  319. if (arr[i] == val) {
  320. isContains= true;
  321. break;
  322. }
  323. }
  324. return isContains;
  325. }
  326. var arrIndexOf = function(arr,val) {
  327. var isContains = this.arrContainsVal(arr,val);
  328. if (isContains) {
  329. return arr.indexOf(val);
  330. } else{
  331. return -1;
  332. }
  333. }
  334. export function navBack() {
  335. uni.navigateBack({
  336. animationType: 'pop-out',
  337. animationDuration: 200
  338. });
  339. }
  340. export function navTo(url) {
  341. uni.navigateTo({
  342. url: url
  343. });
  344. }
  345. export function loginNavTo(url){
  346. if(isLogin()){
  347. uni.navigateTo({
  348. url: url
  349. });
  350. }else{
  351. this.$showLoginPage();
  352. }
  353. }
  354. export function loginCallBack(){
  355. if(isLogin()){
  356. callBack();
  357. }else{
  358. this.$showLoginPage();
  359. }
  360. }
  361. /**
  362. * 获取用户信息
  363. *
  364. */
  365. export function getUserInfo(){
  366. let userInfo=uni.getStorageSync('userInfo');
  367. if(userInfo&&JSON.stringify(userInfo)!='{}') {
  368. userInfo= JSON.parse(userInfo);
  369. } else {
  370. userInfo= {}
  371. }
  372. return userInfo;
  373. };
  374. export function parseIdCard(idCard) {
  375. var str = idCard.substr(0,4)+"****"+idCard.substr(8);
  376. return str;
  377. }
  378. /**
  379. * 获取腕表用户信息
  380. *
  381. */
  382. export function getUser(callback) {
  383. getWatchUserInfo({isFamily:false}).then(res => {
  384. if (res.code == 200) {
  385. uni.setStorageSync("userWatchInfo", JSON.stringify(res.user))
  386. callback(res.user)
  387. } else {
  388. callback({})
  389. }
  390. })
  391. }
  392. /**
  393. * type == 1表示 00:00 改成0, 01:00 改成1, 23:00 改成23格式
  394. * type != 1表示 0 改成00:00, 1 改成01:00, 23 改成23:00格式
  395. */
  396. export function formatHour(time,type) {
  397. if(type == 1) {
  398. const parts = time.split(":");
  399. const hour = parseInt(parts[0]);
  400. return hour;
  401. } else {
  402. let str = time.toString();
  403. if (str.length === 1) {
  404. str = '0' + str;
  405. }
  406. return str + ':00';
  407. }
  408. }
  409. var bdCallBack=function(data,bdCmdType) {
  410. bdCallBackReq(data).then(res => {
  411. if(res.code==200){
  412. uni.setStorageSync("bdCmdType",bdCmdType);
  413. if(bdCmdType==2){
  414. uni.setStorageSync("bdCmdType",3);
  415. }
  416. }else{
  417. uni.showToast({
  418. icon:'none',
  419. title: res.msg
  420. });
  421. }
  422. });
  423. }
  424. var bdAdvFeedback=function(aType,aValue,bdCmdType,userId) { //获取设备的各种标识码
  425. let devinfo=uni.getDeviceInfo();
  426. console.log("qxj bdAdvFeedback devInfo:"+JSON.stringify(devinfo));
  427. let that=this;
  428. // #ifdef APP-PLUS
  429. idCode.getIdCodes(res => {
  430. console.log("qxj getIdCodes:"+JSON.stringify(res));
  431. if (res.data) {
  432. let params={"oaid":res.data.OAID,"model":devinfo.model,"osType":2,"aType":aType,"aValue":aValue.toString()};
  433. if(!!userId){
  434. params["userId"]=userId;
  435. }
  436. bdCallBack(params,bdCmdType);
  437. }
  438. });
  439. // #endif
  440. }
  441. export function registerIdCode(aType,bdCmdType,aValue,userId) {
  442. //bdCmdType -1未操作 0:激活 1:已注册 2:已下单 3:已回传
  443. //注册,先注册再获取,注意APP合规性,若最终用户未同意隐私政策则不要调用
  444. // #ifdef APP-PLUS
  445. let that=this;
  446. idCode.register(res => {
  447. console.log(res);
  448. bdAdvFeedback(aType,aValue,bdCmdType,userId);
  449. });
  450. // #endif
  451. }
  452. export function dateFormatStr(fmt, date){
  453. let dateStr=dateFormat(fmt,date);
  454. return dateStr;
  455. }
  456. // 设置tabbar消息红点
  457. export async function updateMsgDot(){
  458. const resOther = await getLastAndReadStatus()
  459. let num1 = resOther.data && resOther.data.unReadNum ? resOther.data.unReadNum : 0
  460. const resCourse = await getSopCourseStudyList({pageNum: 1,pageSize: 10})
  461. let num2 = resCourse.isNotRead || 0
  462. const imUnred = uni.getStorageSync("imUnread") || 0;
  463. let BadgeNumber = (num1 + num2+imUnred) > 0 ? num1 + num2+imUnred : -1;
  464. //BadgeNumber=num2;
  465. const status = BadgeNumber > 0 ? 1 : 0;
  466. // console.log("--qxj num1:"+num1+" num2:"+num2);
  467. // 获取当前页面实例(通常在页面生命周期或方法中调用)
  468. const currentPages = getCurrentPages();
  469. const currentPage = currentPages[currentPages.length - 1];
  470. const currentRoute = currentPage.route;
  471. const formattedRoute = `/${currentRoute}`;
  472. const isTabBarPage = tabBarPages.includes(formattedRoute);
  473. return;
  474. if(isTabBarPage) {
  475. if(status == 1) {
  476. uni.showTabBarRedDot({
  477. index: 0,
  478. });
  479. } else {
  480. uni.hideTabBarRedDot({
  481. index: 0,
  482. });
  483. }
  484. }
  485. // #ifdef APP-PLUS
  486. plus.runtime.setBadgeNumber(BadgeNumber)
  487. // #endif
  488. }
  489. // 绑定销售
  490. export function handleBindCompanyFsUser(comUserId) {
  491. bindCompanyFsUser(comUserId).then(res=>{
  492. if(res.code == 200) {
  493. uni.navigateTo({
  494. url: '/pages/user/bindCompanyUser'
  495. })
  496. } else {
  497. uni.showToast({
  498. title: res.msg,
  499. icon: 'none'
  500. })
  501. }
  502. // #ifdef APP-PLUS
  503. plus.runtime.arguments = ''
  504. // #endif
  505. }).catch(()=>{
  506. // #ifdef APP-PLUS
  507. plus.runtime.arguments = ''
  508. // #endif
  509. })
  510. }
  511. // 设置来源
  512. export function setSource() {
  513. // #ifdef APP-PLUS
  514. let historyApp = plus.runtime.channel || 'app'
  515. if(plus.os.name == 'iOS'){
  516. historyApp="iOS";
  517. }
  518. updateHistoryApp({historyApp:historyApp})
  519. // #endif
  520. }
  521. // 设置来源
  522. export function companyUserIsLogin() {
  523. let companyUser = uni.getStorageSync('companyUser');
  524. if(!!companyUser && companyUser!=''){
  525. return true;
  526. }
  527. return false;
  528. }
  529. // 关闭订单
  530. export function finishTransaction(transaction, iapChannel) {
  531. console.log("关闭订单")
  532. return new Promise((resolve, reject) => {
  533. iapChannel.finishTransaction(transaction, (res) => {
  534. console.log("关闭订单成功", res)
  535. resolve(res);
  536. }, (err) => {
  537. reject(err);
  538. });
  539. });
  540. }
  541. // 初始化注册到企业微信
  542. export function registerQW(callback,shareItem) {
  543. let schema = getApp().globalData.shareSchema;//应用跳转标识,显示在具体应用下的 Schema字段
  544. let appid = getApp().globalData.shareCorpId;//企业唯一标识。创建企业后显示在,我的企业 CorpID字段
  545. let agentid = getApp().globalData.shareAgentid;//应用唯一标识。显示在具体应用下的 AgentId字段
  546. console.log(schema, appid, agentid)
  547. if(!schema||!appid||!agentid) {
  548. uni.showToast({
  549. title: "企业微信配置不正确",
  550. icon: "none"
  551. })
  552. return
  553. }
  554. sdkwx.registerApp(schema, appid, agentid);
  555. isAppInstalledShare(callback,shareItem)
  556. }
  557. function uploadFilePromise(url) {
  558. return new Promise((resolve, reject) => {
  559. let a = uni.uploadFile({
  560. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  561. filePath: url,
  562. name: 'file',
  563. formData: {
  564. user: 'test'
  565. },
  566. success: (res) => {
  567. resolve(JSON.parse(res.data).url)
  568. },
  569. fail: (e) => {
  570. uni.showToast({
  571. title: "分享失败",
  572. icon: "none"
  573. })
  574. }
  575. });
  576. })
  577. }
  578. //检测是否安装企业微信并分享
  579. function isAppInstalledShare(callback,shareItem) {
  580. sdkwx.isAppInstalled(async function(ret) {
  581. if (ret) {
  582. // 处理图片
  583. let newImg = ''
  584. const isHttp = typeof shareItem.imageUrl === 'string' && shareItem.imageUrl.startsWith("http");
  585. if(isHttp) {
  586. newImg = shareItem.imageUrl
  587. } else {
  588. newImg = await uploadFilePromise(shareItem.imageUrl)
  589. }
  590. newImg = newImg+"?imageMogr2/thumbnail/300x"
  591. // console.log('企业微信已安装');
  592. if(shareItem.isMini) {
  593. let appid_gh = getApp().globalData.shareAppid_gh;//必须是应用关联的小程序,注意要有@app后缀
  594. const path = shareItem.path.replace(/\?/g, '.html?')
  595. // 分享到小程序
  596. uni.downloadFile({
  597. url: newImg,
  598. success: (images)=> {
  599. let imagePath = plus.io.convertLocalFileSystemURL(images.tempFilePath)
  600. sdkwx.shareMiniProgram({
  601. username:appid_gh,//必须是应用关联的小程序,注意要有@app后缀
  602. title: shareItem.title,
  603. hdImageData:imagePath,
  604. path:path
  605. }, (resp) => {
  606. // console.log("分享到小程序",JSON.stringify(resp));
  607. if(resp&&resp.errCode == 5) {
  608. uni.showToast({
  609. title: JSON.stringify(resp),
  610. icon: "none",
  611. duration: 2000
  612. })
  613. } else {
  614. if (typeof callback === 'function') {
  615. callback(ret);
  616. }
  617. }
  618. });
  619. },
  620. fail: (e) => {
  621. uni.showToast({
  622. title: "分享失败",
  623. icon: "none"
  624. })
  625. }
  626. });
  627. } else {
  628. // 分享链接
  629. let thumbUrl = newImg;
  630. let webpageUrl = shareItem.url;
  631. let title = shareItem.title;
  632. let description = shareItem.summary;
  633. try{
  634. sdkwx.shareLink(thumbUrl, webpageUrl, title, description);
  635. if (typeof callback === 'function') {
  636. callback(ret);
  637. }
  638. } catch (e) {
  639. console.log(e)
  640. }
  641. }
  642. } else {
  643. uni.showToast({
  644. title: "未安装企业微信",
  645. icon: "error"
  646. })
  647. }
  648. });
  649. }
  650. export function checkWechatInstalled(){
  651. let isInstalled=false;
  652. if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
  653. isInstalled=true;
  654. }
  655. return isInstalled;
  656. }
  657. export function isAndroid(){
  658. const systemInfo = uni.getSystemInfoSync();
  659. let isAndroid = systemInfo.platform === 'android';
  660. return isAndroid;
  661. }
  662. export function isIos(){
  663. const systemInfo = uni.getSystemInfoSync();
  664. let isIos = systemInfo.platform === 'ios';
  665. return isIos;
  666. }
  667. export function getCurrentPage(){
  668. const pages = getCurrentPages();
  669. const currentPage = pages.length ? pages[pages.length - 1] : null;
  670. const currentRoute = currentPage?.route || '';
  671. return currentRoute;
  672. }
  673. export function isAgreePrivacy(){
  674. // #ifdef APP-PLUS
  675. if(isAndroid()){
  676. return plus.runtime.isAgreePrivacy();
  677. }
  678. else{
  679. return true;
  680. }
  681. // #endif
  682. return true;
  683. }
  684. // 直播模块h
  685. //直播静默登录
  686. export function checkLiveToken(){
  687. var token = uni.getStorageSync('liveToken');
  688. if (token == null || token == undefined || token == "") {
  689. return false;
  690. }
  691. return true;
  692. }
  693. /**
  694. * 随机字符串
  695. *
  696. */
  697. export function generateRandomString(length) {
  698. let result = '';
  699. const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  700. const charactersLength = characters.length;
  701. for (let i = 0; i < length; i++) {
  702. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  703. }
  704. return result;
  705. }