common.js 18 KB

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