人民医院前端

helper.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /* eslint-disable */
  2. import mRouter from '@/utils/router';
  3. import mStore from '@/store';
  4. import appShare from '@/utils/share';
  5. import {
  6. http
  7. } from '@/utils/request';
  8. import pageData from "@/pages/myTask/repairList/addRepair/pageData.js"
  9. export default {
  10. /**
  11. * toast提示
  12. */
  13. toast(title, duration = 3000, mask = false, icon = 'none') {
  14. if (Boolean(title) === false) {
  15. return;
  16. }
  17. uni.showToast({
  18. title,
  19. duration,
  20. mask,
  21. icon
  22. });
  23. },
  24. httpPost(url, params, index) {
  25. http.post(url, params).then((res) => {
  26. if (res.state.toLowerCase() === "success") {
  27. uni.hideLoading()
  28. uni.showToast({
  29. title: '操作成功',
  30. duration: 500
  31. });
  32. setTimeout(() => {
  33. uni.$emit("updateList", {}); //列表刷新数据
  34. uni.navigateBack({
  35. delta: index,
  36. })
  37. }, 500)
  38. }
  39. })
  40. },
  41. httpGetDetail(url, type, workorderid, fn) {
  42. const params = {
  43. type,
  44. workorderid,
  45. token: uni.getStorageSync("token"),
  46. }
  47. http.get(url, params).then((response) => {
  48. if (response.state.toLowerCase() === "success") {
  49. fn(response.data)
  50. }
  51. }).catch((e) => {
  52. console.log(e);
  53. })
  54. },
  55. // 详情返回页面 参数表示页面回退几级
  56. returnPage(index) {
  57. uni.navigateBack({
  58. delta: index,
  59. })
  60. },
  61. // 通过子级部门id获取父级
  62. callback(treeData, id){
  63. for (let i = 0; i < treeData.length; i++) {
  64. if (Number(treeData[i].id) == Number(id)) {
  65. return [treeData[i].text]
  66. } else {
  67. if (treeData[i].children) {
  68. var res = this.callback(treeData[i].children, id)
  69. if (res !== undefined) {
  70. return res.concat(treeData[i].text)
  71. }
  72. }
  73. }
  74. }
  75. },
  76. findParents(treeData, id) {
  77. let string = ''
  78. if (treeData.length == 0) return
  79. if (id == undefined) return
  80. if(this.callback(treeData, id) !== undefined) {
  81. this.callback(treeData, id).reverse().forEach((v,n) => {
  82. string += v + '/'
  83. })
  84. }
  85. const text = (string.substring(string.length - 1) == '/') ? string.substring(0, string.length - 1) : string;
  86. return text
  87. },
  88. findUserName(data, id) {
  89. let string = ''
  90. if (!id) {
  91. return ''
  92. } else {
  93. data.forEach((v, n) => {
  94. if (v.value == id) {
  95. string = v.text
  96. }
  97. })
  98. }
  99. return string
  100. },
  101. //获取当前时间
  102. CurentTime() {
  103. const now = new Date();
  104. const year = now.getFullYear(); //年
  105. const month = now.getMonth() + 1; //月 .toString().padstart(2,0)
  106. const day = now.getDate().toString().padStart(2, 0); //日
  107. const hh = now.getHours().toString().padStart(2, 0); //时
  108. const mm = now.getMinutes().toString().padStart(2, 0); //分
  109. const ss = now.getSeconds().toString().padStart(2, 0); //秒
  110. return year + "-" + month.toString().padStart(2, 0) + "-" + day + " " + hh + ":" + mm + ":" + ss;
  111. },
  112. //获取当前时间年月份
  113. CurentTimeType() {
  114. const now = new Date();
  115. const year = now.getFullYear(); //年
  116. const month = now.getMonth() + 1; //月 .toString().padstart(2,0)
  117. const day = now.getDate().toString().padStart(2, 0); //日
  118. const hh = now.getHours().toString().padStart(2, 0); //时
  119. const mm = now.getMinutes().toString().padStart(2, 0); //分
  120. const ss = now.getSeconds().toString().padStart(2, 0); //秒
  121. return year + "年" + month.toString().padStart(2, 0) + "月" + day + "日" + hh + "时" + mm + "分" + ss + "秒";
  122. },
  123. /**
  124. * 返回上一页携带参数
  125. */
  126. prePage(index) {
  127. let pages = getCurrentPages();
  128. let prePage = pages[pages.length - (index || 2)];
  129. // #ifdef H5
  130. return prePage;
  131. // #endif
  132. return prePage.$vm;
  133. },
  134. /**
  135. * 开发环境全局打印日志
  136. * @param {Object} title
  137. */
  138. log(title) {
  139. if (process.env.NODE_ENV === 'development' && Boolean(title) === true) {
  140. console.log(JSON.stringify(title));
  141. }
  142. },
  143. /**
  144. * 异步获取设备信息
  145. */
  146. getInfoAsync() {
  147. return new Promise((resolve, reject) => {
  148. plus.device.getInfo({
  149. success(e) {
  150. resolve(e);
  151. },
  152. fail(e) {
  153. reject(e.message);
  154. }
  155. });
  156. });
  157. },
  158. /**
  159. * 安卓10不支持IMEI,则获取OAID
  160. */
  161. getOaidAsync() {
  162. return new Promise((resolve, reject) => {
  163. plus.device.getOAID({
  164. success(e) {
  165. resolve(e);
  166. },
  167. fail(e) {
  168. reject(e.message);
  169. }
  170. });
  171. });
  172. },
  173. /**
  174. * 获取一个随机数
  175. * @param {Object} min
  176. * @param {Object} max
  177. */
  178. random(min, max) {
  179. switch (arguments.length) {
  180. case 1:
  181. return parseInt(Math.random() * min + 1, 10);
  182. break;
  183. case 2:
  184. return parseInt(Math.random() * (max - min + 1) + min, 10);
  185. break;
  186. default:
  187. return 0;
  188. break;
  189. }
  190. },
  191. /**
  192. * 获取ios的IDFA
  193. */
  194. getIdfa() {
  195. let idfa = '';
  196. try {
  197. if ('iOS' == plus.os.name) {
  198. let manager = plus.ios.invoke('ASIdentifierManager', 'sharedManager');
  199. if (plus.ios.invoke(manager, 'isAdvertisingTrackingEnabled')) {
  200. let identifier = plus.ios.invoke(manager, 'advertisingIdentifier');
  201. idfa = plus.ios.invoke(identifier, 'UUIDString');
  202. plus.ios.deleteObject(identifier);
  203. }
  204. plus.ios.deleteObject(manager);
  205. }
  206. } catch (e) {
  207. console.error('获取idfa失败');
  208. }
  209. return idfa;
  210. },
  211. /*
  212. * obj 转 params字符串参数
  213. * 例子:{a:1,b:2} => a=1&b=2
  214. */
  215. objParseParam(obj) {
  216. let paramsStr = '';
  217. if (obj instanceof Array) return paramsStr;
  218. if (!(obj instanceof Object)) return paramsStr;
  219. for (let key in obj) {
  220. paramsStr += `${key}=${obj[key]}&`;
  221. }
  222. return paramsStr.substring(0, paramsStr.length - 1);
  223. },
  224. /*
  225. * obj 转 路由地址带参数
  226. * 例子:{a:1,b:2} => /pages/index/index?a=1&b=2
  227. */
  228. objParseUrlAndParam(path, obj) {
  229. let url = path || '/';
  230. let paramsStr = '';
  231. if (obj instanceof Array) return url;
  232. if (!(obj instanceof Object)) return url;
  233. paramsStr = this.objParseParam(obj);
  234. paramsStr && (url += '?');
  235. url += paramsStr;
  236. return url;
  237. },
  238. /*
  239. * 获取url字符串参数
  240. */
  241. getRequestParameters(locationhref) {
  242. let href = locationhref || '';
  243. let theRequest = new Object();
  244. let str = href.split('?')[1];
  245. if (str != undefined) {
  246. let strs = str.split('&');
  247. for (let i = 0; i < strs.length; i++) {
  248. theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1];
  249. }
  250. }
  251. return theRequest;
  252. },
  253. /**
  254. * 加密字符串
  255. */
  256. strEncode(str) {
  257. const key = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  258. let l = key.length;
  259. let a = key.split('');
  260. let s = '',
  261. b,
  262. b1,
  263. b2,
  264. b3;
  265. for (let i = 0; i < str.length; i++) {
  266. b = str.charCodeAt(i);
  267. b1 = b % l;
  268. b = (b - b1) / l;
  269. b2 = b % l;
  270. b = (b - b2) / l;
  271. b3 = b % l;
  272. s += a[b3] + a[b2] + a[b1];
  273. }
  274. return s;
  275. },
  276. /**
  277. * 解密字符串
  278. */
  279. strDecode(str) {
  280. const key = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  281. let l = key.length;
  282. let b,
  283. b1,
  284. b2,
  285. b3,
  286. d = 0,
  287. s;
  288. s = new Array(Math.floor(str.length / 3));
  289. b = s.length;
  290. for (let i = 0; i < b; i++) {
  291. b1 = key.indexOf(str.charAt(d));
  292. d++;
  293. b2 = key.indexOf(str.charAt(d));
  294. d++;
  295. b3 = key.indexOf(str.charAt(d));
  296. d++;
  297. s[i] = b1 * l * l + b2 * l + b3;
  298. }
  299. b = eval('String.fromCharCode(' + s.join(',') + ')');
  300. return b;
  301. },
  302. /**
  303. * 比较版本号
  304. */
  305. compareVersion(reqV, curV) {
  306. if (curV && reqV) {
  307. let arr1 = curV.split('.'),
  308. arr2 = reqV.split('.');
  309. let minLength = Math.min(arr1.length, arr2.length),
  310. position = 0,
  311. diff = 0;
  312. while (
  313. position < minLength &&
  314. (diff = parseInt(arr1[position]) - parseInt(arr2[position])) == 0
  315. ) {
  316. position++;
  317. }
  318. diff = diff != 0 ? diff : arr1.length - arr2.length;
  319. if (diff > 0) {
  320. if (position == minLength - 1) {
  321. return 1;
  322. } else {
  323. return 2;
  324. }
  325. } else {
  326. return 0;
  327. }
  328. } else {
  329. return 0;
  330. }
  331. },
  332. /**
  333. * H5复制
  334. */
  335. h5Copy(content) {
  336. let textarea = document.createElement('textarea');
  337. textarea.value = content;
  338. textarea.readOnly = 'readOnly';
  339. document.body.appendChild(textarea);
  340. textarea.select(); // 选择对象
  341. textarea.setSelectionRange(0, content.length); //核心
  342. let result = document.execCommand('Copy'); // 执行浏览器复制命令
  343. textarea.remove();
  344. const msg = result ? '复制成功' : '复制失败';
  345. this.toast(msg);
  346. },
  347. /**
  348. * app分享
  349. */
  350. handleAppShare(shareUrl, shareTitle, shareContent, shareImg) {
  351. let shareData = {
  352. shareUrl,
  353. shareTitle,
  354. shareContent,
  355. shareImg
  356. };
  357. appShare(shareData, res => {});
  358. },
  359. // 去掉字符串中的空格
  360. trim(str) {
  361. if (!str) {
  362. return '';
  363. }
  364. return str.replace(/\s*/g, '');
  365. },
  366. // 判断两个对象是否相同
  367. isObjectValueEqual(x, y) {
  368. // 指向同一内存时
  369. if (x === y) {
  370. return true;
  371. } else if (
  372. typeof x == 'object' &&
  373. x != null &&
  374. typeof y == 'object' && y != null
  375. ) {
  376. if (Object.keys(x).length != Object.keys(y).length) return false;
  377. for (var prop in x) {
  378. if (y.hasOwnProperty(prop)) {
  379. if (!this.isObjectValueEqual(x[prop], y[prop])) return false;
  380. } else return false;
  381. }
  382. return true;
  383. } else return false;
  384. },
  385. platformGroupFilter() {
  386. let platformGroup = 'wechat';
  387. // #ifdef H5
  388. platformGroup = 'h5';
  389. // #endif
  390. // #ifdef MP-QQ
  391. platformGroup = 'qqMp';
  392. // #endif
  393. // #ifdef MP-WEIXIN
  394. platformGroup = 'wechatMp';
  395. // #endif
  396. // #ifdef MP-ALIPAY
  397. platformGroup = 'aliMp';
  398. // #endif
  399. // #ifdef MP-QQ
  400. platformGroup = 'qqMp';
  401. // #endif
  402. // #ifdef MP-BAIDU
  403. platformGroup = 'baiduMp';
  404. // #endif
  405. // #ifdef APP-PLUS
  406. switch (uni.getSystemInfoSync().platform) {
  407. case 'android':
  408. platformGroup = 'android';
  409. break;
  410. case 'ios':
  411. platformGroup = 'ios';
  412. break;
  413. }
  414. // #endif
  415. return platformGroup;
  416. }
  417. };