Global.js 13 KB

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