common.js 19 KB

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