You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

450 lines
12 KiB

5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
  1. var SIGN_REGEXP = /([yMdhsmH])(\1*)/g
  2. var DEFAULT_PATTERN = 'yyyy-MM-dd'
  3. function padding(s, len) {
  4. var len = len - (s + '').length
  5. for (var i = 0; i < len; i++) {
  6. s = '0' + s
  7. }
  8. return s
  9. }
  10. export default {
  11. /**
  12. * 通过字典值获取其名称
  13. * 界面上可以
  14. * {{formatDicts(dicts,'xxx',scope.row.xxx)}}
  15. * @param {*} dicts
  16. * @param {*} itemCode
  17. * @param {*} cellValue
  18. * @returns
  19. */
  20. formatDicts: function(dicts,itemCode,cellValue){
  21. let key=itemCode;
  22. if( dicts[key]==undefined || dicts[key]==null || dicts[key].length==0 ){
  23. return cellValue;
  24. }
  25. let dict=dicts[key].find(i=>i.id===cellValue)
  26. if(dict){
  27. return dict.name
  28. }else{
  29. return cellValue
  30. }
  31. },
  32. /**
  33. * 通过字典值获取其名称返回根值相同的字典,并自动计算其对应显示样式
  34. * 界面上可以类似使用
  35. * 显示
  36. <el-tag v-for="(item,index) in formatDictsWithClass(dicts,'xxxx',scope.row.xxxx)" :key="index" :type="item.className">{{item.name}}</el-tag>
  37. * 下拉框
  38. <el-select v-model="editForm.xxxx" @change="editSomeFields(editForm,'xxxx',$event)">
  39. <el-option v-for="(item,index) in dicts['xxxx']" :key="index" :value="item.id" :label="item.name"></el-option>
  40. </el-select>
  41. *
  42. * @param {*} dicts
  43. * @param {*} itemCode
  44. * @param {*} cellValue
  45. * @returns [{id:'',name:'',className:''}]
  46. */
  47. formatDictsWithClass: function(dicts,itemCode,cellValue){
  48. var classNames=['info','primary','success','warning','danger'];
  49. let key=itemCode;
  50. if(!cellValue){
  51. return [];
  52. }
  53. if(dicts[key]==undefined || dicts[key]==null || dicts[key].length==0 ){
  54. var className=cellValue%5;
  55. return [{id:cellValue,name:cellValue,className:classNames[cellValue%5]}];
  56. }
  57. let data=dicts[key].find(i=>i.id===cellValue)
  58. let index=dicts[key].findIndex(i=>i.id===cellValue)
  59. if(data){
  60. data['className']=classNames[index%5]
  61. return [data];
  62. }else{
  63. return [{id:cellValue,name:cellValue,className:classNames[cellValue%5]}]
  64. }
  65. },
  66. calcTableMaxHeight(cssSelector) {
  67. var table=cssSelector;
  68. if(typeof cssSelector == 'string'){
  69. table=document.querySelector(cssSelector);
  70. }
  71. var innerHeight=window.innerHeight
  72. var defaultInnerHeight=616;
  73. var pageHeight=32/defaultInnerHeight*innerHeight
  74. var top=148/defaultInnerHeight*innerHeight;
  75. var bottomHeight=32/defaultInnerHeight*innerHeight
  76. if(table!=null){
  77. var rect=table.getBoundingClientRect()
  78. if(rect && rect.top!=0){
  79. top=rect.top;
  80. }
  81. }
  82. var maxTableHeight =innerHeight-top-pageHeight-bottomHeight;
  83. return maxTableHeight;
  84. },
  85. getPositionTop(node) {
  86. if(!node){
  87. return 0;
  88. }
  89. var rect=node.getBoundingClientRect()
  90. var top=rect.top;
  91. if(top==0){
  92. return 0;
  93. }
  94. return top;
  95. },
  96. /**
  97. * 获取时间的前后几分钟
  98. * @param {starTime,endTime} string yyyy-MM-dd HH:ss string yyyy-MM-dd HH:ss
  99. * @return {formatdate} string
  100. */
  101. timeDifference(starTime, endTime) {
  102. //转成时间戳
  103. if (starTime) {
  104. let starDate = new Date(starTime),
  105. endDate = new Date(endTime)
  106. let starStamps = starDate.getTime(),
  107. endStamps = endDate.getTime(),
  108. betweenStamps = ''
  109. betweenStamps = Math.abs((parseInt(endStamps - starStamps)))
  110. let minute = parseInt(betweenStamps / 60000) //取分钟
  111. return minute
  112. } else {
  113. console.log('时间空')
  114. }
  115. },
  116. /**
  117. * 获取时间的前后几分钟
  118. * @param {dateTime,type,minuteNum} string yyyy-MM-dd HH:mm:ss string number
  119. * @return {formatdate} string
  120. */
  121. getAboutTime(dateTime, minuteNum) {
  122. let string = dateTime.replace(/-/g, "/"),
  123. date = new Date(string),
  124. timeStamps = '',
  125. dateObj = '',
  126. hour = '',
  127. minute = '',
  128. formatdate = ''
  129. timeStamps = date.setTime(date.getTime() - parseInt(minuteNum) * 60000)
  130. dateObj = new Date(timeStamps)
  131. hour = dateObj.getHours()
  132. if (hour < 10) {
  133. hour = '0' + hour
  134. }
  135. minute = dateObj.getMinutes()
  136. if (minute < 10) {
  137. minute = '0' + minute
  138. }
  139. formatdate = hour + ":" + minute //设置时间格式
  140. return formatdate
  141. },
  142. //时间2020-09-30
  143. getDate() {
  144. var date = new Date()
  145. var myyear = date.getFullYear();
  146. var mymonth = date.getMonth() + 1;
  147. var myweekday = date.getDate();
  148. if (mymonth < 10) {
  149. mymonth = "0" + mymonth;
  150. }
  151. if (myweekday < 10) {
  152. myweekday = "0" + myweekday;
  153. }
  154. return (myyear + "-" + mymonth + "-" + myweekday);
  155. },
  156. getQueryStringByName: function(name) {
  157. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
  158. var r = window.location.search.substr(1).match(reg)
  159. var context = ''
  160. if (r != null) {
  161. context = r[2]
  162. }
  163. reg = null
  164. r = null
  165. return context == null || context == '' || context == 'undefined' ? '' : context
  166. },
  167. fmoney(s, n) {
  168. n = n > 0 && n <= 20 ? n : 2;
  169. s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  170. var l = s.split(".")[0].split("").reverse(),
  171. r = s.split(".")[1];
  172. var t = "";
  173. for (let i = 0; i < l.length; i++) {
  174. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  175. }
  176. return t.split("").reverse().join("") + "." + r;
  177. },
  178. isNull(obj) {
  179. if (obj === null || obj === '' || obj === undefined) {
  180. return true;
  181. }
  182. return false;
  183. },
  184. /**
  185. * 字段转成驼峰命名
  186. * @param {*} name
  187. */
  188. toCamel(name) {
  189. return name.replace(/\_(\w)/g, function(all, letter) {
  190. return letter.toUpperCase();
  191. });
  192. },
  193. /**
  194. * 驼峰转下横线
  195. * @param {*} name
  196. */
  197. toLine(name) {
  198. return name.replace(/([A-Z])/g, "_$1").toLowerCase();
  199. },
  200. formatDate: function(date, pattern) {
  201. pattern = pattern || DEFAULT_PATTERN
  202. return pattern.replace(SIGN_REGEXP, function($0) {
  203. switch ($0.charAt(0)) {
  204. case 'y':
  205. return padding(date.getFullYear(), $0.length)
  206. case 'M':
  207. return padding(date.getMonth() + 1, $0.length)
  208. case 'd':
  209. return padding(date.getDate(), $0.length)
  210. case 'w':
  211. return date.getDay() + 1
  212. case 'h':
  213. return padding(date.getHours(), $0.length)
  214. case 'H':
  215. return padding(date.getHours(), $0.length)
  216. case 'm':
  217. return padding(date.getMinutes(), $0.length)
  218. case 's':
  219. return padding(date.getSeconds(), $0.length)
  220. }
  221. })
  222. },
  223. parseDate: function(dateString, pattern) {
  224. var matchs1 = pattern.match(SIGN_REGEXP)
  225. var matchs2 = dateString.match(/(\d)+/g)
  226. if (matchs1.length == matchs2.length) {
  227. var _date = new Date(1970, 0, 1)
  228. for (var i = 0; i < matchs1.length; i++) {
  229. var _int = parseInt(matchs2[i])
  230. var sign = matchs1[i]
  231. switch (sign.charAt(0)) {
  232. case 'y':
  233. _date.setFullYear(_int);
  234. break
  235. case 'M':
  236. _date.setMonth(_int - 1);
  237. break
  238. case 'd':
  239. _date.setDate(_int);
  240. break
  241. case 'h':
  242. _date.setHours(_int);
  243. break
  244. case 'm':
  245. _date.setMinutes(_int);
  246. break
  247. case 's':
  248. _date.setSeconds(_int);
  249. break
  250. }
  251. }
  252. return _date
  253. }
  254. return null
  255. },
  256. //type date/daterange
  257. getPickerOptions: function(type) {
  258. if (type != 'datarange') {
  259. var shortcuts = [{
  260. text: '今天',
  261. onClick(picker) {
  262. picker.$emit('pick', new Date());
  263. }
  264. }, {
  265. text: '昨天',
  266. onClick(picker) {
  267. const date = new Date();
  268. date.setTime(date.getTime() - 3600 * 1000 * 24);
  269. picker.$emit('pick', date);
  270. }
  271. }, {
  272. text: '前一周',
  273. onClick(picker) {
  274. const date = new Date();
  275. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
  276. picker.$emit('pick', date);
  277. }
  278. }, {
  279. text: '前两周',
  280. onClick(picker) {
  281. const date = new Date();
  282. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7 * 2);
  283. picker.$emit('pick', date);
  284. }
  285. }, {
  286. text: '前四周',
  287. onClick(picker) {
  288. const date = new Date();
  289. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7 * 4);
  290. picker.$emit('pick', date);
  291. }
  292. }, {
  293. text: '后一周',
  294. onClick(picker) {
  295. const date = new Date();
  296. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
  297. picker.$emit('pick', date);
  298. }
  299. }, {
  300. text: '后两周',
  301. onClick(picker) {
  302. const date = new Date();
  303. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7 * 2);
  304. picker.$emit('pick', date);
  305. }
  306. }, {
  307. text: '后一月',
  308. onClick(picker) {
  309. const date = new Date();
  310. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7 * 4);
  311. picker.$emit('pick', date);
  312. }
  313. }, {
  314. text: '后两月',
  315. onClick(picker) {
  316. const date = new Date();
  317. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7 * 8);
  318. picker.$emit('pick', date);
  319. }
  320. }, {
  321. text: '后四月',
  322. onClick(picker) {
  323. const date = new Date();
  324. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7 * 16);
  325. picker.$emit('pick', date);
  326. }
  327. }]
  328. return {
  329. shortcuts: shortcuts
  330. };
  331. } else {
  332. var shortcuts = [{
  333. text: "前一周",
  334. onClick(picker) {
  335. const end = new Date();
  336. const start = new Date();
  337. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  338. picker.$emit("pick", [start, end]);
  339. }
  340. },
  341. {
  342. text: "前两周",
  343. onClick(picker) {
  344. const end = new Date();
  345. const start = new Date();
  346. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7 * 2);
  347. picker.$emit("pick", [start, end]);
  348. }
  349. },
  350. {
  351. text: "前三周",
  352. onClick(picker) {
  353. const end = new Date();
  354. const start = new Date();
  355. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7 * 3);
  356. picker.$emit("pick", [start, end]);
  357. }
  358. },
  359. {
  360. text: "前一个月",
  361. onClick(picker) {
  362. const end = new Date();
  363. const start = new Date();
  364. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  365. picker.$emit("pick", [start, end]);
  366. }
  367. },
  368. {
  369. text: "前三个月",
  370. onClick(picker) {
  371. const end = new Date();
  372. const start = new Date();
  373. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  374. picker.$emit("pick", [start, end]);
  375. }
  376. },
  377. {
  378. text: "后一周",
  379. onClick(picker) {
  380. const end = new Date();
  381. const start = new Date();
  382. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
  383. picker.$emit("pick", [start, end]);
  384. }
  385. },
  386. {
  387. text: "后两周",
  388. onClick(picker) {
  389. const end = new Date();
  390. const start = new Date();
  391. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7 * 2);
  392. picker.$emit("pick", [start, end]);
  393. }
  394. },
  395. {
  396. text: "后三周",
  397. onClick(picker) {
  398. const end = new Date();
  399. const start = new Date();
  400. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7 * 3);
  401. picker.$emit("pick", [start, end]);
  402. }
  403. },
  404. {
  405. text: "后一个月",
  406. onClick(picker) {
  407. const end = new Date();
  408. const start = new Date();
  409. end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
  410. picker.$emit("pick", [start, end]);
  411. }
  412. },
  413. {
  414. text: "后三个月",
  415. onClick(picker) {
  416. const end = new Date();
  417. const start = new Date();
  418. end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
  419. picker.$emit("pick", [start, end]);
  420. }
  421. }
  422. ]
  423. return {
  424. shortcuts: shortcuts
  425. };;
  426. }
  427. },
  428. }