Global.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. // 网站基本信息
  2. companyInfo = {
  3. url: 'http://det.shandongewall.com/',
  4. main: 'alloutlong',
  5. year: new Date().getFullYear(),
  6. };
  7. // 当前版本 演示版
  8. runVersion = 'test';
  9. // 户外版本
  10. // runVersion = 'outDoor';
  11. // normal
  12. // runVersion = 'normal';
  13. // headapi = process.env.NODE_ENV === 'development' ? '/api/' : '../';
  14. // headapi = 'http://192.168.0.110:8080/';//从郑伟那里获得数据源
  15. // headapi = '';//从郑伟那里获得数据源
  16. // headapi = 'http://192.168.0.63:8080/';//从郑伟那里获得数据源
  17. headapi = 'http://192.168.0.10:8080/';//实际场馆默认数据源
  18. // 七牛云imgsrc
  19. imgUrl = "http://qjzpcd34v.hb-bkt.clouddn.com";
  20. // pad测试版本
  21. // 常用选项
  22. globalQuipState = function () {
  23. let option = [
  24. {
  25. value: '',
  26. label: '全部'
  27. }, {
  28. value: '0',
  29. label: '新入库'
  30. }, {
  31. value: '1',
  32. label: '未售'
  33. },
  34. ];
  35. return option
  36. };
  37. // 开始时间
  38. globalBt = function () {
  39. const et = new Date();
  40. const bt = new Date("2019-01-01 00:00:01");
  41. return [bt, et];
  42. };
  43. globalBt2 = function (days) {
  44. const et = new Date();
  45. const bt = new Date();
  46. days = days ? days : 0;
  47. bt.setTime(bt.getTime() - 3600 * 1000 * 24 * days);
  48. return [bt, et];
  49. };
  50. // 格式化时间
  51. globalfmtDate = function (datetime, length) {
  52. if ((datetime == '') || (datetime == undefined))
  53. return '';
  54. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  55. return '';
  56. length = !length ? 10 : length;//缺省参数
  57. return (datetime != null) ? datetime.substr(0, length) : '';
  58. };
  59. getHoursAndMin = function (datetime) {
  60. let date = new Date(datetime);
  61. h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
  62. m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  63. return h + m;
  64. };
  65. getHoursAndMinAndSec = function () {
  66. let date = new Date();
  67. h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
  68. m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
  69. s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  70. return h + m + s;
  71. };
  72. // 格式化时间去掉T
  73. nonTfmtDate = function (datetime, length) {
  74. if ((datetime == '') || (datetime == undefined))
  75. return '';
  76. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  77. return '';
  78. length = !length ? 10 : length;//缺省参数
  79. datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
  80. return datetime
  81. };
  82. // 格式化时间去掉T
  83. nonTfmtDatetoLength = function (datetime, length) {
  84. if ((datetime == '') || (datetime == undefined))
  85. return '';
  86. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  87. return '';
  88. length = !length ? 10 : length;//缺省参数
  89. datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').substr(0, length);
  90. return datetime
  91. };
  92. // 获取当前时间
  93. globalcurrent = function () {
  94. let date = new Date();
  95. let seperator1 = "-";
  96. let year = date.getFullYear();
  97. let month = date.getMonth() + 1;
  98. let strDate = date.getDate();
  99. if (month >= 1 && month <= 9) {
  100. month = "0" + month;
  101. }
  102. if (strDate >= 0 && strDate <= 9) {
  103. strDate = "0" + strDate;
  104. }
  105. let thisdata = year + seperator1 + month + seperator1 + strDate;
  106. return thisdata;
  107. };
  108. // 校验内容长度
  109. globalValid = function (data, mins, maxs, text, that) {
  110. let thisVal = data;
  111. let thisLeng = thisVal.length;
  112. let min = parseInt(mins);
  113. let max = parseInt(maxs);
  114. let dispalyMin = min + 1;
  115. let title = '警告';
  116. if (thisVal == '') {
  117. that.$message({
  118. message: text + '不能为空!',
  119. type: 'warning'
  120. });
  121. return false
  122. } else if (thisLeng <= min) {
  123. that.$message({
  124. message: text + '最少' + dispalyMin + '字符!',
  125. type: 'warning'
  126. });
  127. return false
  128. } else if (thisLeng > max) {
  129. that.$message({
  130. message: text + '超出限制数量!',
  131. type: 'warning'
  132. });
  133. return false
  134. } else {
  135. return true
  136. }
  137. };
  138. // 手机号码格式
  139. globalCheckPhone = function (val) {
  140. let re = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  141. val = val.toString();
  142. if (val.search(re) == -1) {
  143. return false;
  144. } else {
  145. return true;
  146. }
  147. };
  148. getNowDate = function () {
  149. let date = new Date();
  150. let y = date.getFullYear();
  151. let m = date.getMonth() + 1;
  152. let d = date.getDate();
  153. let H = date.getHours();
  154. let mm = date.getMinutes();
  155. let s = date.getSeconds()
  156. m = m < 10 ? "0" + m : m;
  157. d = d < 10 ? "0" + d : d;
  158. // H = H < 10 ? "0" + H : H;
  159. return y + "年" + m + "月" + d + "日";
  160. }
  161. globalcurrentWeek = function () {
  162. let weeks = new Date().getDay();
  163. let d = new Date().getDate();
  164. return getNowDate() + ' ' + numberToWeekdays(weeks) + ' 第' + getWeekOfYear() + '周';
  165. }
  166. getWeekOfYear = function () {
  167. var today = new Date();
  168. var firstDay = new Date(today.getFullYear(), 0, 1);
  169. var dayOfWeek = firstDay.getDay();
  170. var spendDay = 1;
  171. if (dayOfWeek != 0) {
  172. spendDay = 7 - dayOfWeek + 1;
  173. }
  174. firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
  175. var d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
  176. var result = Math.ceil(d / 7);
  177. return result + 1;
  178. };
  179. // table配置项目
  180. // 每页选项
  181. pageOptions = function () {
  182. let option = [
  183. {
  184. value: 10,
  185. label: '10'
  186. }, {
  187. value: 25,
  188. label: '25'
  189. }, {
  190. value: 50,
  191. label: '50'
  192. }, {
  193. value: 100,
  194. label: '100'
  195. }, {
  196. value: 2000,
  197. label: '2000'
  198. },
  199. ];
  200. return option
  201. };
  202. // 到期日
  203. endTypeOptions = function () {
  204. let option = [
  205. {
  206. value: '',
  207. label: '全部'
  208. }, {
  209. value: 1,
  210. label: '当天'
  211. }, {
  212. value: 7,
  213. label: '一周'
  214. }, {
  215. value: 30,
  216. label: '一个月'
  217. }, {
  218. value: 90,
  219. label: '一季度'
  220. }, {
  221. value: 180,
  222. label: '半年'
  223. },
  224. ];
  225. return option
  226. }
  227. //会员类型
  228. vipOptions = function (i) {
  229. let option = [];
  230. if (i == 0) {
  231. option = [
  232. {
  233. value: '',
  234. label: '全部'
  235. }, {
  236. value: 1,
  237. label: '年费会员'
  238. }, {
  239. value: 2,
  240. label: '充值会员'
  241. },
  242. ];
  243. } else {
  244. option = [
  245. {
  246. value: 1,
  247. label: '年费会员'
  248. }, {
  249. value: 2,
  250. label: '充值会员'
  251. },
  252. ];
  253. }
  254. return option
  255. }
  256. turnResToOption = function (data) {
  257. if (!data) return false
  258. let ids = data.map(item => {
  259. return {
  260. label: item.UserInfo.Name + ' ' + item.UserInfo.Phone,
  261. key: parseInt(item.UserInfo.Id),
  262. value: parseInt(item.UserInfo.Id),
  263. }
  264. })
  265. return ids
  266. }
  267. turnResToOptionByViper = function (data) {
  268. if (!data) return false;
  269. let ids = data.map(item => {
  270. return {
  271. label: item.Name + ' ' + item.Phone,
  272. key: parseInt(item.Id),
  273. value: parseInt(item.Id),
  274. }
  275. });
  276. return ids
  277. };
  278. turnResToOptionBySimViper = function (data) {
  279. if (!data) return false;
  280. let ids = data.map(item => {
  281. return {
  282. label: item.Name + ' ' + item.Usercode,
  283. key: parseInt(item.Id),
  284. value: parseInt(item.Id),
  285. RemainHour: parseInt(item.RemainHour),
  286. }
  287. });
  288. return ids
  289. };
  290. turnResToOptionByCoach = function (data) {
  291. if (!data) return false;
  292. let ids = data.map(item => {
  293. return {
  294. label: item.Name + ' ' + item.Phone,
  295. key: parseInt(item.TeacherId),
  296. value: parseInt(item.TeacherId),
  297. }
  298. });
  299. return ids
  300. };
  301. turnResToOptionByUsers = function (data) {
  302. if (!data) return false;
  303. let ids = data.map(item => {
  304. return {
  305. label: item.Name + ' ' + item.Phone,
  306. key: parseInt(item.Id),
  307. value: parseInt(item.Id),
  308. }
  309. });
  310. return ids
  311. };
  312. turnClassResToOption = function (data) {
  313. if (data == null) return false;
  314. if (!data) return false;
  315. let ids = data.map(item => {
  316. return {
  317. label: item.ClassSelf.ClassName,
  318. key: parseInt(item.ClassSelf.ClassId),
  319. value: parseInt(item.ClassSelf.ClassId),
  320. ClassColor: item.ClassSelf.ClassColor,
  321. }
  322. });
  323. return ids
  324. };
  325. turnShopResToOption = function (data) {
  326. if (!data) return false
  327. let ids = data.map(item => {
  328. return {
  329. label: item.ShopName,
  330. key: parseInt(item.ShopID),
  331. value: parseInt(item.ShopID)
  332. }
  333. });
  334. return ids
  335. };
  336. turnStdToOption = function (data) {
  337. if (!data) return false;
  338. let ids = data.map(item => {
  339. return {
  340. label: item.ClassName + '(' + item.BeginStr + '-' + item.EndStr + ')',
  341. key: parseInt(item.StdId),
  342. value: parseInt(item.StdId),
  343. classId: parseInt(item.ClassId),
  344. }
  345. });
  346. return ids
  347. };
  348. numberToWeekdays = function (val) {
  349. switch (parseInt(val)) {
  350. case 1:
  351. return '星期一';
  352. break;
  353. case 2:
  354. return '星期二';
  355. break;
  356. case 3:
  357. return '星期三';
  358. break;
  359. case 4:
  360. return '星期四';
  361. break;
  362. case 5:
  363. return '星期五';
  364. break;
  365. case 6:
  366. return '星期六';
  367. break;
  368. case 0:
  369. return '星期天';
  370. break;
  371. }
  372. };
  373. // 随机背景
  374. RandomBg = function () {
  375. let bgClassNum = parseInt(Math.random() * 4) + 1;
  376. return 'bgStyle' + bgClassNum + ' pages';
  377. };
  378. RandomBg2 =function(){
  379. let bgClassNum = parseInt(Math.random() * 4) + 1;
  380. return 'bg2Style' + bgClassNum + ' pages';
  381. };
  382. // 运动强度
  383. sportLevel = function (val) {
  384. let colorClass = '';
  385. let per = parseInt(val);
  386. switch (true) {
  387. case per >= 90:
  388. colorClass = 'red';
  389. break;
  390. case per <= 89 && per > 79:
  391. colorClass = 'brown';
  392. break;
  393. case per <= 79 && per > 69:
  394. colorClass = 'yellow';
  395. break;
  396. case per <= 69 && per > 54:
  397. colorClass = 'green';
  398. break;
  399. case per <= 54 && per > 39:
  400. colorClass = 'violet';
  401. break;
  402. case per <= 39:
  403. colorClass = 'blue';
  404. break
  405. }
  406. return colorClass
  407. };
  408. // 假数据生成器
  409. fakeNews = function (num, team) {
  410. let item = [];
  411. let nums = Math.random() * 100 + 1;
  412. let teamNum = team == 3 ? 3 : 2;
  413. for (var i = 0; i < num; i++) {
  414. item.push(
  415. {
  416. "SvId": 1,
  417. "UserId": 1,
  418. "Cle": parseInt(Math.random() * 100 + 50),
  419. "realHr1": parseInt(Math.random() * 100 + 50),
  420. "activePercent": parseInt(Math.random() * 100 + 50),
  421. "realHr": parseInt(Math.random() * 100 + 50),
  422. "heartRate": parseInt(Math.random() * 100 + 50),
  423. "PureCalorieNoVo2": parseInt(Math.random() * 100 + 50),
  424. "Name": "测试人",
  425. "name": "测试人",
  426. "updateTime": 1604568915582,
  427. "Ck": (nums + i + 1) * 2.2,
  428. "formatCk": parseInt(Math.random() * 100 + 50),
  429. "Head": "http://192.168.0.2/gc.png",
  430. "GroupNo": i % teamNum + 1,
  431. "Sex": i % 2 + 1,
  432. "IsBirthday": i % 2
  433. }
  434. )
  435. }
  436. return item;
  437. };
  438. // 欢迎新同学
  439. OpenStudent = function (msg, that) {
  440. that.studentInfo.Rs = msg;
  441. that.studentInfo.dialogVisible = true;
  442. // 倒计时5秒自动关闭
  443. let studentTime = 6;
  444. let clock = window.setInterval(() => {
  445. studentTime--;
  446. let num = (6 - studentTime) / 6 * 100;
  447. this.studentInfo.percent = num > 100 ? 100 : num;
  448. console.log('num' + num);
  449. console.log('studentTime' + this.studentTime);
  450. if (parseInt(studentTime) < 0) {
  451. that.studentInfo.dialogVisible = false;
  452. clearInterval(clock);
  453. }
  454. }, 1000)
  455. };
  456. // 深拷贝
  457. deepClone = function (obj) {
  458. let _obj = JSON.stringify(obj),
  459. objClone = JSON.parse(_obj);
  460. return objClone
  461. };