common.js 18 KB

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