common.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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. const urlToObj = function(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. /**
  370. * 判断是否为空对象
  371. * @param {Object} 时间字符串
  372. */
  373. var isNullObj = function(obj) {
  374. let isNull = (JSON.stringify(obj) == "{}");
  375. return isNull;
  376. }
  377. var arrContainsVal = function(arr, val) {
  378. var isContains = false;
  379. for (var i = 0; i < arr.length; i++) {
  380. if (arr[i] == val) {
  381. isContains = true;
  382. break;
  383. }
  384. }
  385. return isContains;
  386. }
  387. var arrIndexOf = function(arr, val) {
  388. var isContains = this.arrContainsVal(arr, val);
  389. if (isContains) {
  390. return arr.indexOf(val);
  391. } else {
  392. return -1;
  393. }
  394. }
  395. export function navBack() {
  396. uni.navigateBack({
  397. animationType: 'pop-out',
  398. animationDuration: 200
  399. });
  400. }
  401. export function navTo(url) {
  402. uni.navigateTo({
  403. url: url
  404. });
  405. }
  406. export function loginNavTo(url) {
  407. if (isLogin()) {
  408. uni.navigateTo({
  409. url: url
  410. });
  411. } else {
  412. this.$showLoginPage();
  413. }
  414. }
  415. export function loginCallBack() {
  416. if (isLogin()) {
  417. callBack();
  418. } else {
  419. this.$showLoginPage();
  420. }
  421. }
  422. /**
  423. * 获取用户信息
  424. *
  425. */
  426. export function getUserInfo() {
  427. let userInfo = uni.getStorageSync('userInfo');
  428. if (userInfo && JSON.stringify(userInfo) != '{}') {
  429. userInfo = JSON.parse(userInfo);
  430. } else {
  431. userInfo = {}
  432. }
  433. return userInfo;
  434. };
  435. export function parseIdCard(idCard) {
  436. var str = idCard.substr(0, 4) + "****" + idCard.substr(8);
  437. return str;
  438. }
  439. /**
  440. * 获取腕表用户信息
  441. *
  442. */
  443. export function getUser(callback) {
  444. getWatchUserInfo({
  445. isFamily: false
  446. }).then(res => {
  447. if (res.code == 200) {
  448. uni.setStorageSync("userWatchInfo", JSON.stringify(res.user))
  449. callback(res.user)
  450. } else {
  451. callback({})
  452. }
  453. })
  454. }
  455. /**
  456. * type == 1表示 00:00 改成0, 01:00 改成1, 23:00 改成23格式
  457. * type != 1表示 0 改成00:00, 1 改成01:00, 23 改成23:00格式
  458. */
  459. export function formatHour(time, type) {
  460. if (type == 1) {
  461. const parts = time.split(":");
  462. const hour = parseInt(parts[0]);
  463. return hour;
  464. } else {
  465. let str = time.toString();
  466. if (str.length === 1) {
  467. str = '0' + str;
  468. }
  469. return str + ':00';
  470. }
  471. }
  472. var bdCallBack = function(data, bdCmdType) {
  473. bdCallBackReq(data).then(res => {
  474. if (res.code == 200) {
  475. uni.setStorageSync("bdCmdType", bdCmdType);
  476. if (bdCmdType == 2) {
  477. uni.setStorageSync("bdCmdType", 3);
  478. }
  479. } else {
  480. uni.showToast({
  481. icon: 'none',
  482. title: res.msg
  483. });
  484. }
  485. });
  486. }
  487. var bdAdvFeedback = function(aType, aValue, bdCmdType, userId) { //获取设备的各种标识码
  488. let devinfo = uni.getDeviceInfo();
  489. console.log("qxj bdAdvFeedback devInfo:" + JSON.stringify(devinfo));
  490. let that = this;
  491. // #ifdef APP-PLUS
  492. idCode.getIdCodes(res => {
  493. console.log("qxj getIdCodes:" + JSON.stringify(res));
  494. if (res.data) {
  495. let params = {
  496. "oaid": res.data.OAID,
  497. "model": devinfo.model,
  498. "osType": 2,
  499. "aType": aType,
  500. "aValue": aValue.toString()
  501. };
  502. if (!!userId) {
  503. params["userId"] = userId;
  504. }
  505. bdCallBack(params, bdCmdType);
  506. }
  507. });
  508. // #endif
  509. }
  510. export function registerIdCode(aType, bdCmdType, aValue, userId) {
  511. //bdCmdType -1未操作 0:激活 1:已注册 2:已下单 3:已回传
  512. //注册,先注册再获取,注意APP合规性,若最终用户未同意隐私政策则不要调用
  513. // #ifdef APP-PLUS
  514. let that = this;
  515. idCode.register(res => {
  516. console.log(res);
  517. bdAdvFeedback(aType, aValue, bdCmdType, userId);
  518. });
  519. // #endif
  520. }
  521. export function dateFormatStr(fmt, date) {
  522. let dateStr = dateFormat(fmt, date);
  523. return dateStr;
  524. }
  525. // 设置tabbar消息红点
  526. export async function updateMsgDot() {
  527. const resOther = await getLastAndReadStatus()
  528. let num1 = resOther.data && resOther.data.unReadNum ? resOther.data.unReadNum : 0
  529. const resCourse = await getSopCourseStudyList({
  530. pageNum: 1,
  531. pageSize: 10
  532. })
  533. let num2 = resCourse.isNotRead || 0
  534. const imUnred = uni.getStorageSync("imUnread") || 0;
  535. let BadgeNumber = (num1 + num2 + imUnred) > 0 ? num1 + num2 + imUnred : -1;
  536. //BadgeNumber=num2;
  537. const status = BadgeNumber > 0 ? 1 : 0;
  538. // console.log("--qxj num1:"+num1+" num2:"+num2);
  539. // 获取当前页面实例(通常在页面生命周期或方法中调用)
  540. const currentPages = getCurrentPages();
  541. const currentPage = currentPages[currentPages.length - 1];
  542. const currentRoute = currentPage.route;
  543. const formattedRoute = `/${currentRoute}`;
  544. const isTabBarPage = tabBarPages.includes(formattedRoute);
  545. return;
  546. if (isTabBarPage) {
  547. if (status == 1) {
  548. uni.showTabBarRedDot({
  549. index: 0,
  550. });
  551. } else {
  552. uni.hideTabBarRedDot({
  553. index: 0,
  554. });
  555. }
  556. }
  557. // #ifdef APP-PLUS
  558. plus.runtime.setBadgeNumber(BadgeNumber)
  559. // #endif
  560. }
  561. // 绑定销售
  562. export function handleBindCompanyFsUser(comUserId) {
  563. bindCompanyFsUser(comUserId).then(res => {
  564. if (res.code == 200) {
  565. uni.navigateTo({
  566. url: '/pages/user/bindCompanyUser'
  567. })
  568. } else {
  569. uni.showToast({
  570. title: res.msg,
  571. icon: 'none'
  572. })
  573. }
  574. // #ifdef APP-PLUS
  575. plus.runtime.arguments = ''
  576. // #endif
  577. }).catch(() => {
  578. // #ifdef APP-PLUS
  579. plus.runtime.arguments = ''
  580. // #endif
  581. })
  582. }
  583. // 设置来源
  584. export function setSource() {
  585. // #ifdef APP-PLUS
  586. let historyApp = plus.runtime.channel || 'app'
  587. if (plus.os.name == 'iOS') {
  588. historyApp = "iOS";
  589. }
  590. console.log("qxj setSource");
  591. updateHistoryApp({
  592. historyApp: historyApp
  593. })
  594. // #endif
  595. }
  596. // 设置来源
  597. export function companyUserIsLogin() {
  598. let companyUser = uni.getStorageSync('companyUser');
  599. if (!!companyUser && companyUser != '') {
  600. return true;
  601. }
  602. return false;
  603. }
  604. // 关闭订单
  605. export function finishTransaction(transaction, iapChannel) {
  606. console.log("关闭订单")
  607. return new Promise((resolve, reject) => {
  608. iapChannel.finishTransaction(transaction, (res) => {
  609. console.log("关闭订单成功", res)
  610. resolve(res);
  611. }, (err) => {
  612. reject(err);
  613. });
  614. });
  615. }
  616. // 初始化注册到企业微信
  617. export function registerQW(callback, shareItem) {
  618. let schema = getApp().globalData.shareSchema; //应用跳转标识,显示在具体应用下的 Schema字段
  619. let appid = getApp().globalData.shareCorpId; //企业唯一标识。创建企业后显示在,我的企业 CorpID字段
  620. let agentid = getApp().globalData.shareAgentid; //应用唯一标识。显示在具体应用下的 AgentId字段
  621. console.log(schema, appid, agentid)
  622. if (!schema || !appid || !agentid) {
  623. uni.showToast({
  624. title: "企业微信配置不正确",
  625. icon: "none"
  626. })
  627. return
  628. }
  629. sdkwx.registerApp(schema, appid, agentid);
  630. isAppInstalledShare(callback, shareItem)
  631. }
  632. function uploadFilePromise(url) {
  633. return new Promise((resolve, reject) => {
  634. let a = uni.uploadFile({
  635. url: uni.getStorageSync('requestPath') + '/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  636. filePath: url,
  637. name: 'file',
  638. formData: {
  639. user: 'test'
  640. },
  641. success: (res) => {
  642. resolve(JSON.parse(res.data).url)
  643. },
  644. fail: (e) => {
  645. uni.showToast({
  646. title: "分享失败",
  647. icon: "none"
  648. })
  649. }
  650. });
  651. })
  652. }
  653. //检测是否安装企业微信并分享
  654. function isAppInstalledShare(callback, shareItem) {
  655. sdkwx.isAppInstalled(async function(ret) {
  656. if (ret) {
  657. // 处理图片
  658. let newImg = ''
  659. const isHttp = typeof shareItem.imageUrl === 'string' && shareItem.imageUrl.startsWith("http");
  660. if (isHttp) {
  661. newImg = shareItem.imageUrl
  662. } else {
  663. newImg = await uploadFilePromise(shareItem.imageUrl)
  664. }
  665. newImg = newImg + "?imageMogr2/thumbnail/300x"
  666. // console.log('企业微信已安装');
  667. if (shareItem.isMini) {
  668. let appid_gh = getApp().globalData.shareAppid_gh; //必须是应用关联的小程序,注意要有@app后缀
  669. const path = shareItem.path.replace(/\?/g, '.html?')
  670. // 分享到小程序
  671. uni.downloadFile({
  672. url: newImg,
  673. success: (images) => {
  674. let imagePath = plus.io.convertLocalFileSystemURL(images.tempFilePath)
  675. sdkwx.shareMiniProgram({
  676. username: appid_gh, //必须是应用关联的小程序,注意要有@app后缀
  677. title: shareItem.title,
  678. hdImageData: imagePath,
  679. path: path
  680. }, (resp) => {
  681. // console.log("分享到小程序",JSON.stringify(resp));
  682. if (resp && resp.errCode == 5) {
  683. uni.showToast({
  684. title: JSON.stringify(resp),
  685. icon: "none",
  686. duration: 2000
  687. })
  688. } else {
  689. if (typeof callback === 'function') {
  690. callback(ret);
  691. }
  692. }
  693. });
  694. },
  695. fail: (e) => {
  696. uni.showToast({
  697. title: "分享失败",
  698. icon: "none"
  699. })
  700. }
  701. });
  702. } else {
  703. // 分享链接
  704. let thumbUrl = newImg;
  705. let webpageUrl = shareItem.url;
  706. let title = shareItem.title;
  707. let description = shareItem.summary;
  708. try {
  709. sdkwx.shareLink(thumbUrl, webpageUrl, title, description);
  710. if (typeof callback === 'function') {
  711. callback(ret);
  712. }
  713. } catch (e) {
  714. console.log(e)
  715. }
  716. }
  717. } else {
  718. uni.showToast({
  719. title: "未安装企业微信",
  720. icon: "error"
  721. })
  722. }
  723. });
  724. }
  725. export function checkWechatInstalled() {
  726. let isInstalled = false;
  727. if (plus.runtime.isApplicationExist({
  728. pname: 'com.tencent.mm',
  729. action: 'weixin://'
  730. })) {
  731. isInstalled = true;
  732. }
  733. return isInstalled;
  734. }
  735. export function isAndroid() {
  736. const systemInfo = uni.getSystemInfoSync();
  737. let isAndroid = systemInfo.platform === 'android';
  738. return isAndroid;
  739. }
  740. export function isIos() {
  741. const systemInfo = uni.getSystemInfoSync();
  742. let isIos = systemInfo.platform === 'ios';
  743. return isIos;
  744. }
  745. export function isAgreePrivacy(){
  746. // #ifdef APP-PLUS
  747. if(isAndroid()){
  748. return plus.runtime.isAgreePrivacy();
  749. }
  750. else{
  751. return true;
  752. }
  753. // #endif
  754. return true;
  755. }