ylyx-cli 1.0.16 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/README.md +313 -276
  2. package/bin/ylyx.js +176 -168
  3. package/lib/config.js +325 -283
  4. package/lib/deploy.js +509 -529
  5. package/lib/environments.js +111 -0
  6. package/lib/generator.js +192 -192
  7. package/lib/index.js +113 -113
  8. package/lib/interactive.js +87 -87
  9. package/lib/remote.js +179 -179
  10. package/lib/template.js +174 -174
  11. package/lib/utils.js +148 -148
  12. package/package.json +61 -59
  13. package/templates/react-app/files/.gitignore +22 -0
  14. package/templates/react-app/files/README.md +23 -23
  15. package/templates/react-app/files/package.json +28 -28
  16. package/templates/react-app/files/public/index.html +11 -11
  17. package/templates/react-app/files/src/App.css +15 -15
  18. package/templates/react-app/files/src/App.js +15 -15
  19. package/templates/react-app/files/src/index.css +10 -10
  20. package/templates/react-app/files/src/index.js +11 -11
  21. package/templates/react-app/template.json +11 -11
  22. package/templates/react-component/files/Component.module.css +5 -5
  23. package/templates/react-component/files/Component.tsx +31 -31
  24. package/templates/react-component/files/index.ts +2 -2
  25. package/templates/react-component/template.json +48 -48
  26. package/templates/vue-app/files/.editorconfig +14 -14
  27. package/templates/vue-app/files/.env.development +21 -21
  28. package/templates/vue-app/files/.env.production +18 -18
  29. package/templates/vue-app/files/.eslintignore +5 -5
  30. package/templates/vue-app/files/.eslintrc.js +267 -267
  31. package/templates/vue-app/files/.gitignore +24 -0
  32. package/templates/vue-app/files/.prettierignore +11 -11
  33. package/templates/vue-app/files/.travis.yml +5 -5
  34. package/templates/vue-app/files/.vscode/extensions.json +7 -7
  35. package/templates/vue-app/files/.vscode/settings.json +39 -39
  36. package/templates/vue-app/files/LICENSE +191 -191
  37. package/templates/vue-app/files/README.md +87 -87
  38. package/templates/vue-app/files/babel.config.js +11 -11
  39. package/templates/vue-app/files/jest.config.js +24 -24
  40. package/templates/vue-app/files/package.json +136 -136
  41. package/templates/vue-app/files/plopfile.js +7 -7
  42. package/templates/vue-app/files/postcss.config.js +5 -5
  43. package/templates/vue-app/files/public/default.js +25 -25
  44. package/templates/vue-app/files/public/index.html +26 -26
  45. package/templates/vue-app/files/src/App.vue +54 -54
  46. package/templates/vue-app/files/src/api/bigDataV/index.js +198 -198
  47. package/templates/vue-app/files/src/api/data.js +42 -42
  48. package/templates/vue-app/files/src/api/dataArchive/index.js +186 -186
  49. package/templates/vue-app/files/src/api/generator/genConfig.js +16 -16
  50. package/templates/vue-app/files/src/api/generator/generator.js +32 -32
  51. package/templates/vue-app/files/src/api/indexManagement/index.js +39 -39
  52. package/templates/vue-app/files/src/api/institutionMonitor/index.js +396 -396
  53. package/templates/vue-app/files/src/api/institutionSet/index.js +120 -120
  54. package/templates/vue-app/files/src/api/login.js +44 -44
  55. package/templates/vue-app/files/src/api/selfStatistics/index.js +50 -50
  56. package/templates/vue-app/files/src/api/system/code.js +15 -15
  57. package/templates/vue-app/files/src/api/system/dict.js +34 -34
  58. package/templates/vue-app/files/src/api/system/dictDetail.js +52 -52
  59. package/templates/vue-app/files/src/api/system/equipment.js +35 -35
  60. package/templates/vue-app/files/src/api/system/examManage.js +49 -49
  61. package/templates/vue-app/files/src/api/system/examProject.js +48 -48
  62. package/templates/vue-app/files/src/api/system/hosModel.js +35 -35
  63. package/templates/vue-app/files/src/api/system/hospital.js +88 -88
  64. package/templates/vue-app/files/src/api/system/job.js +40 -40
  65. package/templates/vue-app/files/src/api/system/menu.js +67 -67
  66. package/templates/vue-app/files/src/api/system/model.js +42 -42
  67. package/templates/vue-app/files/src/api/system/risConfig.js +9 -9
  68. package/templates/vue-app/files/src/api/system/role.js +64 -64
  69. package/templates/vue-app/files/src/api/system/sysSet.js +19 -19
  70. package/templates/vue-app/files/src/api/system/timing.js +41 -41
  71. package/templates/vue-app/files/src/api/system/user.js +121 -121
  72. package/templates/vue-app/files/src/api/tools/alipay.js +25 -25
  73. package/templates/vue-app/files/src/api/tools/email.js +24 -24
  74. package/templates/vue-app/files/src/api/tools/localStorage.js +27 -27
  75. package/templates/vue-app/files/src/api/tools/qiniu.js +40 -40
  76. package/templates/vue-app/files/src/assets/css/font-awesome.css +2342 -2342
  77. package/templates/vue-app/files/src/assets/css/font-awesome.min.css +2336 -2336
  78. package/templates/vue-app/files/src/assets/fonts/fontawesome-webfont.svg +2671 -2671
  79. package/templates/vue-app/files/src/assets/icons/index.js +9 -9
  80. package/templates/vue-app/files/src/assets/icons/svg/hospital.svg +1 -1
  81. package/templates/vue-app/files/src/assets/icons/svg/hospital1.svg +1 -1
  82. package/templates/vue-app/files/src/assets/icons/svg/loginOne.svg +35 -35
  83. package/templates/vue-app/files/src/assets/icons/svg/loginOneWhite.svg +19 -19
  84. package/templates/vue-app/files/src/assets/icons/svg/loginOr.svg +93 -93
  85. package/templates/vue-app/files/src/assets/icons/svg/loginUp.svg +96 -96
  86. package/templates/vue-app/files/src/assets/icons/svg/monitor.svg +1 -1
  87. package/templates/vue-app/files/src/assets/icons/svg/offline.svg +1 -1
  88. package/templates/vue-app/files/src/assets/icons/svg/online.svg +1 -1
  89. package/templates/vue-app/files/src/assets/icons/svg/system.svg +1 -1
  90. package/templates/vue-app/files/src/assets/icons/svgo.yml +21 -21
  91. package/templates/vue-app/files/src/assets/styles/btn.scss +103 -103
  92. package/templates/vue-app/files/src/assets/styles/eladmin.scss +124 -124
  93. package/templates/vue-app/files/src/assets/styles/element-ui.scss +217 -217
  94. package/templates/vue-app/files/src/assets/styles/element-variables.scss +31 -31
  95. package/templates/vue-app/files/src/assets/styles/global.scss +73 -73
  96. package/templates/vue-app/files/src/assets/styles/index.scss +220 -220
  97. package/templates/vue-app/files/src/assets/styles/mixin.scss +60 -60
  98. package/templates/vue-app/files/src/assets/styles/publicStyle.scss +224 -224
  99. package/templates/vue-app/files/src/assets/styles/sidebar.scss +239 -239
  100. package/templates/vue-app/files/src/assets/styles/transition.scss +48 -48
  101. package/templates/vue-app/files/src/assets/styles/variables.scss +44 -44
  102. package/templates/vue-app/files/src/common/flexible.js +145 -145
  103. package/templates/vue-app/files/src/components/Breadcrumb/index.vue +87 -87
  104. package/templates/vue-app/files/src/components/Crud/CRUD.operation.vue +248 -248
  105. package/templates/vue-app/files/src/components/Crud/Pagination.vue +20 -20
  106. package/templates/vue-app/files/src/components/Crud/RR.operation.vue +39 -39
  107. package/templates/vue-app/files/src/components/Crud/UD.operation.vue +106 -106
  108. package/templates/vue-app/files/src/components/Crud/crud.js +907 -907
  109. package/templates/vue-app/files/src/components/Crud/user/UR.operation.vue +154 -154
  110. package/templates/vue-app/files/src/components/DateRangePicker/index.vue +42 -42
  111. package/templates/vue-app/files/src/components/DateRangePickerProhibitNext/index.vue +42 -42
  112. package/templates/vue-app/files/src/components/DateRangePickerProhibitTodayNext/index.vue +48 -48
  113. package/templates/vue-app/files/src/components/Dict/Dict.js +31 -31
  114. package/templates/vue-app/files/src/components/Dict/index.js +29 -29
  115. package/templates/vue-app/files/src/components/Doc/index.vue +16 -16
  116. package/templates/vue-app/files/src/components/Echarts/BarChart.vue +115 -115
  117. package/templates/vue-app/files/src/components/Echarts/Category.vue +768 -768
  118. package/templates/vue-app/files/src/components/Echarts/Funnel.vue +120 -120
  119. package/templates/vue-app/files/src/components/Echarts/Gauge.vue +74 -74
  120. package/templates/vue-app/files/src/components/Echarts/Graph.vue +101 -101
  121. package/templates/vue-app/files/src/components/Echarts/HeatMap.vue +301 -301
  122. package/templates/vue-app/files/src/components/Echarts/Line3D.vue +110 -110
  123. package/templates/vue-app/files/src/components/Echarts/PieChart.vue +84 -84
  124. package/templates/vue-app/files/src/components/Echarts/Point.vue +161 -161
  125. package/templates/vue-app/files/src/components/Echarts/RadarChart.vue +123 -123
  126. package/templates/vue-app/files/src/components/Echarts/Rich.vue +160 -160
  127. package/templates/vue-app/files/src/components/Echarts/Sankey.vue +114 -114
  128. package/templates/vue-app/files/src/components/Echarts/Scatter.vue +192 -192
  129. package/templates/vue-app/files/src/components/Echarts/Sunburst.vue +127 -127
  130. package/templates/vue-app/files/src/components/Echarts/ThemeRiver.vue +233 -233
  131. package/templates/vue-app/files/src/components/Echarts/WordCloud.vue +201 -201
  132. package/templates/vue-app/files/src/components/GithubCorner/index.vue +55 -55
  133. package/templates/vue-app/files/src/components/Hamburger/index.vue +44 -44
  134. package/templates/vue-app/files/src/components/HeaderSearch/index.vue +196 -196
  135. package/templates/vue-app/files/src/components/IconSelect/index.vue +74 -74
  136. package/templates/vue-app/files/src/components/IconSelect/requireIcons.js +10 -10
  137. package/templates/vue-app/files/src/components/Iframe/index.vue +30 -30
  138. package/templates/vue-app/files/src/components/JavaEdit/index.vue +78 -78
  139. package/templates/vue-app/files/src/components/Pagination/index.vue +100 -100
  140. package/templates/vue-app/files/src/components/PanThumb/index.vue +149 -149
  141. package/templates/vue-app/files/src/components/ParentView/index.vue +3 -3
  142. package/templates/vue-app/files/src/components/Permission/index.js +13 -13
  143. package/templates/vue-app/files/src/components/Permission/permission.js +21 -21
  144. package/templates/vue-app/files/src/components/RightPanel/index.vue +149 -149
  145. package/templates/vue-app/files/src/components/Screenfull/index.vue +60 -60
  146. package/templates/vue-app/files/src/components/SizeSelect/index.vue +60 -60
  147. package/templates/vue-app/files/src/components/SvgIcon/index.vue +66 -66
  148. package/templates/vue-app/files/src/components/ThemePicker/index.vue +177 -177
  149. package/templates/vue-app/files/src/components/UploadExcel/index.vue +149 -149
  150. package/templates/vue-app/files/src/components/WaterMark/setWaterMark.js +68 -68
  151. package/templates/vue-app/files/src/components/WaterMark/waterMark.vue +69 -69
  152. package/templates/vue-app/files/src/components/Xgplayer/index.vue +49 -49
  153. package/templates/vue-app/files/src/components/YamlEdit/index.vue +81 -81
  154. package/templates/vue-app/files/src/layout/components/AppMain.vue +67 -67
  155. package/templates/vue-app/files/src/layout/components/Navbar.vue +209 -209
  156. package/templates/vue-app/files/src/layout/components/Settings/index.vue +125 -125
  157. package/templates/vue-app/files/src/layout/components/Sidebar/FixiOSBug.js +26 -26
  158. package/templates/vue-app/files/src/layout/components/Sidebar/Item.vue +29 -29
  159. package/templates/vue-app/files/src/layout/components/Sidebar/Link.vue +35 -35
  160. package/templates/vue-app/files/src/layout/components/Sidebar/Logo.vue +93 -93
  161. package/templates/vue-app/files/src/layout/components/Sidebar/SidebarItem.vue +104 -104
  162. package/templates/vue-app/files/src/layout/components/Sidebar/index.vue +79 -79
  163. package/templates/vue-app/files/src/layout/components/TagsView/ScrollPane.vue +90 -90
  164. package/templates/vue-app/files/src/layout/components/TagsView/index.vue +299 -299
  165. package/templates/vue-app/files/src/layout/components/index.js +5 -5
  166. package/templates/vue-app/files/src/layout/index.vue +119 -119
  167. package/templates/vue-app/files/src/layout/mixin/ResizeHandler.js +45 -45
  168. package/templates/vue-app/files/src/main.js +89 -89
  169. package/templates/vue-app/files/src/mixins/crud.js +348 -348
  170. package/templates/vue-app/files/src/router/index.js +156 -156
  171. package/templates/vue-app/files/src/router/routers.js +203 -203
  172. package/templates/vue-app/files/src/settings.js +57 -57
  173. package/templates/vue-app/files/src/store/getters.js +29 -29
  174. package/templates/vue-app/files/src/store/index.js +25 -25
  175. package/templates/vue-app/files/src/store/modules/api.js +33 -33
  176. package/templates/vue-app/files/src/store/modules/app.js +55 -55
  177. package/templates/vue-app/files/src/store/modules/permission.js +79 -79
  178. package/templates/vue-app/files/src/store/modules/register.js +17 -17
  179. package/templates/vue-app/files/src/store/modules/settings.js +46 -46
  180. package/templates/vue-app/files/src/store/modules/tagsView.js +168 -168
  181. package/templates/vue-app/files/src/store/modules/user.js +119 -119
  182. package/templates/vue-app/files/src/utils/auth.js +18 -18
  183. package/templates/vue-app/files/src/utils/base64ToFile.js +27 -27
  184. package/templates/vue-app/files/src/utils/clipboard.js +36 -36
  185. package/templates/vue-app/files/src/utils/datetime.js +289 -289
  186. package/templates/vue-app/files/src/utils/getBlobFile.js +10 -10
  187. package/templates/vue-app/files/src/utils/getTime.js +29 -29
  188. package/templates/vue-app/files/src/utils/index.js +520 -520
  189. package/templates/vue-app/files/src/utils/permission.js +29 -29
  190. package/templates/vue-app/files/src/utils/pinyin.js +450 -450
  191. package/templates/vue-app/files/src/utils/request.js +139 -139
  192. package/templates/vue-app/files/src/utils/rsaEncrypt.js +37 -37
  193. package/templates/vue-app/files/src/utils/shortcuts.js +210 -210
  194. package/templates/vue-app/files/src/utils/upload.js +12 -12
  195. package/templates/vue-app/files/src/utils/validate.js +262 -262
  196. package/templates/vue-app/files/src/views/components/Echarts.vue +124 -124
  197. package/templates/vue-app/files/src/views/components/Editor.vue +75 -75
  198. package/templates/vue-app/files/src/views/components/MarkDown.vue +44 -44
  199. package/templates/vue-app/files/src/views/components/UVideo.vue +37 -37
  200. package/templates/vue-app/files/src/views/components/YamlEdit.vue +206 -206
  201. package/templates/vue-app/files/src/views/components/camera/camera.vue +115 -115
  202. package/templates/vue-app/files/src/views/components/camera/cameraTest.vue +158 -158
  203. package/templates/vue-app/files/src/views/components/excel/upload-excel.vue +41 -41
  204. package/templates/vue-app/files/src/views/components/icons/element-icons.js +74 -74
  205. package/templates/vue-app/files/src/views/components/icons/index.vue +106 -106
  206. package/templates/vue-app/files/src/views/components/icons/svg-icons.js +10 -10
  207. package/templates/vue-app/files/src/views/components/scroll/index.vue +107 -107
  208. package/templates/vue-app/files/src/views/components/scrollFull/index.vue +99 -99
  209. package/templates/vue-app/files/src/views/dashboard/LineChart.vue +138 -138
  210. package/templates/vue-app/files/src/views/dashboard/PanelGroup.vue +173 -173
  211. package/templates/vue-app/files/src/views/dashboard/mixins/resize.js +57 -57
  212. package/templates/vue-app/files/src/views/dataArchive/delTable.vue +354 -354
  213. package/templates/vue-app/files/src/views/dataArchive/exportDetail.vue +121 -121
  214. package/templates/vue-app/files/src/views/dataArchive/exportList.vue +160 -160
  215. package/templates/vue-app/files/src/views/dataArchive/index.vue +2104 -2104
  216. package/templates/vue-app/files/src/views/features/401.vue +83 -83
  217. package/templates/vue-app/files/src/views/features/404.vue +226 -226
  218. package/templates/vue-app/files/src/views/features/redirect.vue +12 -12
  219. package/templates/vue-app/files/src/views/generator/config.vue +348 -348
  220. package/templates/vue-app/files/src/views/generator/index.vue +143 -143
  221. package/templates/vue-app/files/src/views/generator/preview.vue +39 -39
  222. package/templates/vue-app/files/src/views/home.vue +80 -80
  223. package/templates/vue-app/files/src/views/indexManagement/index.vue +422 -422
  224. package/templates/vue-app/files/src/views/indexManagement/other.vue +286 -286
  225. package/templates/vue-app/files/src/views/institutionMonitor/components/LineChart.vue +191 -191
  226. package/templates/vue-app/files/src/views/institutionMonitor/index.scss +339 -339
  227. package/templates/vue-app/files/src/views/institutionMonitor/index.vue +1385 -1385
  228. package/templates/vue-app/files/src/views/institutionMonitor/mixins/resize.js +57 -57
  229. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/checkProjectCode.vue +267 -267
  230. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/imageAbnormalMonitor.vue +361 -361
  231. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/index.vue +686 -686
  232. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/leakageAnomaly.vue +270 -270
  233. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/moveMonitore.vue +114 -114
  234. package/templates/vue-app/files/src/views/institutionMonitor/monitorDetail/qualityMonitore.vue +338 -338
  235. package/templates/vue-app/files/src/views/institutionSet/cloudSet.vue +534 -534
  236. package/templates/vue-app/files/src/views/institutionSet/index.vue +2550 -2550
  237. package/templates/vue-app/files/src/views/login.vue +243 -243
  238. package/templates/vue-app/files/src/views/qualityLogin.vue +280 -280
  239. package/templates/vue-app/files/src/views/selfStatistics/components/LineChart.vue +296 -296
  240. package/templates/vue-app/files/src/views/selfStatistics/hospitalDetail/index.vue +533 -533
  241. package/templates/vue-app/files/src/views/selfStatistics/index.scss +447 -447
  242. package/templates/vue-app/files/src/views/selfStatistics/index.vue +903 -903
  243. package/templates/vue-app/files/src/views/selfStatistics/mixins/resize.js +57 -57
  244. package/templates/vue-app/files/src/views/selfStatistics/monitorDetail/index.vue +285 -285
  245. package/templates/vue-app/files/src/views/selfStatistics/offlineDetail/index.vue +104 -104
  246. package/templates/vue-app/files/src/views/selfStatistics/selfActiveDetail/index.vue +104 -104
  247. package/templates/vue-app/files/src/views/selfStatistics/selfMonitorDetail/index.vue +420 -420
  248. package/templates/vue-app/files/src/views/selfStatistics/setWaterMark/setWaterMark.js +68 -68
  249. package/templates/vue-app/files/src/views/selfStatistics/setWaterMark/waterMark.vue +69 -69
  250. package/templates/vue-app/files/src/views/system/dept/index.vue +144 -144
  251. package/templates/vue-app/files/src/views/system/dict/dictDetail.vue +146 -146
  252. package/templates/vue-app/files/src/views/system/dict/index.vue +159 -159
  253. package/templates/vue-app/files/src/views/system/examModality/index.vue +174 -174
  254. package/templates/vue-app/files/src/views/system/examPart/index.vue +184 -184
  255. package/templates/vue-app/files/src/views/system/examProject/index.vue +321 -321
  256. package/templates/vue-app/files/src/views/system/examine/index.vue +66 -66
  257. package/templates/vue-app/files/src/views/system/job/index.vue +119 -119
  258. package/templates/vue-app/files/src/views/system/job/module/form.vue +72 -72
  259. package/templates/vue-app/files/src/views/system/job/module/header.vue +48 -48
  260. package/templates/vue-app/files/src/views/system/menu/index.vue +327 -327
  261. package/templates/vue-app/files/src/views/system/model/index.vue +285 -285
  262. package/templates/vue-app/files/src/views/system/role/index.vue +434 -434
  263. package/templates/vue-app/files/src/views/system/sysSet/index.vue +84 -84
  264. package/templates/vue-app/files/src/views/system/timing/index.vue +289 -289
  265. package/templates/vue-app/files/src/views/system/timing/log.vue +143 -143
  266. package/templates/vue-app/files/src/views/system/user/admin.vue +414 -414
  267. package/templates/vue-app/files/src/views/system/user/center/updateEmail.vue +146 -146
  268. package/templates/vue-app/files/src/views/system/user/center/updatePass.vue +168 -168
  269. package/templates/vue-app/files/src/views/system/user/center.vue +140 -140
  270. package/templates/vue-app/files/src/views/system/user/index.vue +972 -972
  271. package/templates/vue-app/files/src/views/systemSet/role/index.vue +314 -314
  272. package/templates/vue-app/files/src/views/systemSet/user/admin.vue +414 -414
  273. package/templates/vue-app/files/src/views/systemSet/user/center/updateEmail.vue +146 -146
  274. package/templates/vue-app/files/src/views/systemSet/user/center/updatePass.vue +115 -115
  275. package/templates/vue-app/files/src/views/systemSet/user/center.vue +351 -351
  276. package/templates/vue-app/files/src/views/systemSet/user/index.vue +928 -928
  277. package/templates/vue-app/files/src/views/tools/aliPay/config.vue +102 -102
  278. package/templates/vue-app/files/src/views/tools/aliPay/index.vue +48 -48
  279. package/templates/vue-app/files/src/views/tools/aliPay/toPay.vue +91 -91
  280. package/templates/vue-app/files/src/views/tools/email/config.vue +91 -91
  281. package/templates/vue-app/files/src/views/tools/email/index.vue +42 -42
  282. package/templates/vue-app/files/src/views/tools/email/send.vue +159 -159
  283. package/templates/vue-app/files/src/views/tools/storage/index.vue +35 -35
  284. package/templates/vue-app/files/src/views/tools/storage/local/index.vue +207 -207
  285. package/templates/vue-app/files/src/views/tools/storage/qiniu/form.vue +108 -108
  286. package/templates/vue-app/files/src/views/tools/storage/qiniu/index.vue +241 -241
  287. package/templates/vue-app/files/src/views/tools/swagger/index.vue +14 -14
  288. package/templates/vue-app/files/vue.config.js +173 -173
  289. package/templates/vue-app/template.json +29 -29
@@ -1,520 +1,520 @@
1
- /**
2
- * Created by PanJiaChen on 16/11/18.
3
- */
4
-
5
- /**
6
- * Parse the time to string
7
- * @param {(Object|string|number)} time
8
- * @param {string} cFormat
9
- * @returns {string}
10
- */
11
- export function parseTime(time, cFormat) {
12
- if (!time) return '';
13
- if (arguments.length === 0) {
14
- return null;
15
- }
16
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}';
17
- let date;
18
- if (typeof time === 'undefined' || time === null || time === 'null') {
19
- return '';
20
- } else if (typeof time === 'object') {
21
- date = time;
22
- } else {
23
- if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
24
- time = parseInt(time);
25
- }
26
- if (typeof time === 'number' && time.toString().length === 10) {
27
- time = time * 1000;
28
- }
29
- date = new Date(time);
30
- }
31
- const formatObj = {
32
- y: date.getFullYear(),
33
- m: date.getMonth() + 1,
34
- d: date.getDate(),
35
- h: date.getHours(),
36
- i: date.getMinutes(),
37
- s: date.getSeconds(),
38
- a: date.getDay(),
39
- };
40
- const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
41
- let value = formatObj[key];
42
- // Note: getDay() returns 0 on Sunday
43
- if (key === 'a') {
44
- return ['日', '一', '二', '三', '四', '五', '六'][value];
45
- }
46
- if (result.length > 0 && value < 10) {
47
- value = '0' + value;
48
- }
49
- return value || 0;
50
- });
51
- return time_str;
52
- }
53
-
54
- /**
55
- * @param {number} time
56
- * @param {string} option
57
- * @returns {string}
58
- */
59
- export function formatTime(time, option) {
60
- if (('' + time).length === 10) {
61
- time = parseInt(time) * 1000;
62
- } else {
63
- time = +time;
64
- }
65
- const d = new Date(time);
66
- const now = Date.now();
67
-
68
- const diff = (now - d) / 1000;
69
-
70
- if (diff < 30) {
71
- return '刚刚';
72
- } else if (diff < 3600) {
73
- // less 1 hour
74
- return Math.ceil(diff / 60) + '分钟前';
75
- } else if (diff < 3600 * 24) {
76
- return Math.ceil(diff / 3600) + '小时前';
77
- } else if (diff < 3600 * 24 * 2) {
78
- return '1天前';
79
- }
80
- if (option) {
81
- return parseTime(time, option);
82
- } else {
83
- return (
84
- d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
85
- );
86
- }
87
- }
88
-
89
- /**
90
- * @param {string} url
91
- * @returns {Object}
92
- */
93
- export function getQueryObject(url) {
94
- url = url == null ? window.location.href : url;
95
- const search = url.substring(url.lastIndexOf('?') + 1);
96
- const obj = {};
97
- const reg = /([^?&=]+)=([^?&=]*)/g;
98
- search.replace(reg, (rs, $1, $2) => {
99
- const name = decodeURIComponent($1);
100
- let val = decodeURIComponent($2);
101
- val = String(val);
102
- obj[name] = val;
103
- return rs;
104
- });
105
- return obj;
106
- }
107
-
108
- /**
109
- * @param {string} input value
110
- * @returns {number} output value
111
- */
112
- export function byteLength(str) {
113
- // returns the byte length of an utf8 string
114
- let s = str.length;
115
- for (var i = str.length - 1; i >= 0; i--) {
116
- const code = str.charCodeAt(i);
117
- if (code > 0x7f && code <= 0x7ff) s++;
118
- else if (code > 0x7ff && code <= 0xffff) s += 2;
119
- if (code >= 0xdc00 && code <= 0xdfff) i--;
120
- }
121
- return s;
122
- }
123
-
124
- /**
125
- * @param {Array} actual
126
- * @returns {Array}
127
- */
128
- export function cleanArray(actual) {
129
- const newArray = [];
130
- for (let i = 0; i < actual.length; i++) {
131
- if (actual[i]) {
132
- newArray.push(actual[i]);
133
- }
134
- }
135
- return newArray;
136
- }
137
-
138
- /**
139
- * @param {Object} json
140
- * @returns {Array}
141
- */
142
- export function param(json) {
143
- if (!json) return '';
144
- return cleanArray(
145
- Object.keys(json).map(key => {
146
- if (json[key] === undefined) return '';
147
- return encodeURIComponent(key) + '=' + encodeURIComponent(json[key]);
148
- })
149
- ).join('&');
150
- }
151
-
152
- /**
153
- * @param {string} url
154
- * @returns {Object}
155
- */
156
- export function param2Obj(url) {
157
- const search = url.split('?')[1];
158
- if (!search) {
159
- return {};
160
- }
161
- return JSON.parse(
162
- '{"' +
163
- decodeURIComponent(search)
164
- .replace(/"/g, '\\"')
165
- .replace(/&/g, '","')
166
- .replace(/=/g, '":"')
167
- .replace(/\+/g, ' ') +
168
- '"}'
169
- );
170
- }
171
-
172
- /**
173
- * @param {string} val
174
- * @returns {string}
175
- */
176
- export function html2Text(val) {
177
- const div = document.createElement('div');
178
- div.innerHTML = val;
179
- return div.textContent || div.innerText;
180
- }
181
-
182
- /**
183
- * Merges two objects, giving the last one precedence
184
- * @param {Object} target
185
- * @param {(Object|Array)} source
186
- * @returns {Object}
187
- */
188
- export function objectMerge(target, source) {
189
- if (typeof target !== 'object') {
190
- target = {};
191
- }
192
- if (Array.isArray(source)) {
193
- return source.slice();
194
- }
195
- Object.keys(source).forEach(property => {
196
- const sourceProperty = source[property];
197
- if (typeof sourceProperty === 'object') {
198
- target[property] = objectMerge(target[property], sourceProperty);
199
- } else {
200
- target[property] = sourceProperty;
201
- }
202
- });
203
- return target;
204
- }
205
-
206
- /**
207
- * @param {HTMLElement} element
208
- * @param {string} className
209
- */
210
- export function toggleClass(element, className) {
211
- if (!element || !className) {
212
- return;
213
- }
214
- let classString = element.className;
215
- const nameIndex = classString.indexOf(className);
216
- if (nameIndex === -1) {
217
- classString += '' + className;
218
- } else {
219
- classString =
220
- classString.substr(0, nameIndex) + classString.substr(nameIndex + className.length);
221
- }
222
- element.className = classString;
223
- }
224
-
225
- /**
226
- * @param {string} type
227
- * @returns {Date}
228
- */
229
- export function getTime(type) {
230
- if (type === 'start') {
231
- return new Date().getTime() - 3600 * 1000 * 24 * 90;
232
- } else {
233
- return new Date(new Date().toDateString());
234
- }
235
- }
236
-
237
- /**
238
- * @param {Function} func
239
- * @param {number} wait
240
- * @param {boolean} immediate
241
- * @return {*}
242
- */
243
- export function debounce(func, wait, immediate) {
244
- let timeout, args, context, timestamp, result;
245
-
246
- const later = function () {
247
- // 据上一次触发时间间隔
248
- const last = +new Date() - timestamp;
249
-
250
- // 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
251
- if (last < wait && last > 0) {
252
- timeout = setTimeout(later, wait - last);
253
- } else {
254
- timeout = null;
255
- // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
256
- if (!immediate) {
257
- result = func.apply(context, args);
258
- if (!timeout) context = args = null;
259
- }
260
- }
261
- };
262
-
263
- return function (...args) {
264
- context = this;
265
- timestamp = +new Date();
266
- const callNow = immediate && !timeout;
267
- // 如果延时不存在,重新设定延时
268
- if (!timeout) timeout = setTimeout(later, wait);
269
- if (callNow) {
270
- result = func.apply(context, args);
271
- context = args = null;
272
- }
273
-
274
- return result;
275
- };
276
- }
277
-
278
- /**
279
- * This is just a simple version of deep copy
280
- * Has a lot of edge cases bug
281
- * If you want to use a perfect deep copy, use lodash's _.cloneDeep
282
- * @param {Object} source
283
- * @returns {Object}
284
- */
285
- export function deepClone(source) {
286
- if (!source && typeof source !== 'object') {
287
- throw new Error('error arguments', 'deepClone');
288
- }
289
- const targetObj = source.constructor === Array ? [] : {};
290
- Object.keys(source).forEach(keys => {
291
- if (source[keys] && typeof source[keys] === 'object') {
292
- targetObj[keys] = deepClone(source[keys]);
293
- } else {
294
- targetObj[keys] = source[keys];
295
- }
296
- });
297
- return targetObj;
298
- }
299
-
300
- /**
301
- * @param {Array} arr
302
- * @returns {Array}
303
- */
304
- export function uniqueArr(arr) {
305
- return Array.from(new Set(arr));
306
- }
307
-
308
- /**
309
- * @returns {string}
310
- */
311
- export function createUniqueString() {
312
- const timestamp = +new Date() + '';
313
- const randomNum = parseInt((1 + Math.random()) * 65536) + '';
314
- return (+(randomNum + timestamp)).toString(32);
315
- }
316
-
317
- /**
318
- * Check if an element has a class
319
- * @param {HTMLElement} elm
320
- * @param {string} cls
321
- * @returns {boolean}
322
- */
323
- export function hasClass(ele, cls) {
324
- return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
325
- }
326
-
327
- /**
328
- * Add class to element
329
- * @param {HTMLElement} elm
330
- * @param {string} cls
331
- */
332
- export function addClass(ele, cls) {
333
- if (!hasClass(ele, cls)) ele.className += ' ' + cls;
334
- }
335
-
336
- /**
337
- * Remove class from element
338
- * @param {HTMLElement} elm
339
- * @param {string} cls
340
- */
341
- export function removeClass(ele, cls) {
342
- if (hasClass(ele, cls)) {
343
- const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
344
- ele.className = ele.className.replace(reg, ' ');
345
- }
346
- }
347
-
348
- // 替换邮箱字符
349
- export function regEmail(email) {
350
- if (String(email).indexOf('@') > 0) {
351
- const str = email.split('@');
352
- let _s = '';
353
- if (str[0].length > 3) {
354
- for (var i = 0; i < str[0].length - 3; i++) {
355
- _s += '*';
356
- }
357
- }
358
- var new_email = str[0].substr(0, 3) + _s + '@' + str[1];
359
- }
360
- return new_email;
361
- }
362
-
363
- // 替换手机字符
364
- export function regMobile(mobile) {
365
- if (mobile.length > 7) {
366
- var new_mobile = mobile.substr(0, 3) + '****' + mobile.substr(7);
367
- }
368
- return new_mobile;
369
- }
370
-
371
- // 下载文件
372
- export function downloadFile(obj, name, suffix, isCn) {
373
- const url = window.URL.createObjectURL(new Blob([obj]));
374
- const link = document.createElement('a');
375
- link.style.display = 'none';
376
- link.href = url;
377
- let fileName = null;
378
- console.log(isCn, 'isCn');
379
- if (typeof isCn === 'boolean') {
380
- if (isCn) {
381
- fileName = name + getCNDate() + '.' + suffix;
382
- } else if (!isCn) {
383
- fileName = name + '.' + suffix;
384
- }
385
- } else {
386
- fileName = name + '-' + parseTime(new Date()) + '.' + suffix;
387
- }
388
-
389
- link.setAttribute('download', fileName);
390
- document.body.appendChild(link);
391
- link.click();
392
- document.body.removeChild(link);
393
- }
394
- export function getCNDate() {
395
- var now = new Date();
396
- var year = now.getFullYear(); // 得到年份
397
- var month = now.getMonth(); // 得到月份
398
- var date = now.getDate(); // 得到日期
399
- month = month + 1;
400
- month = month.toString().padStart(2, '0');
401
- date = date.toString().padStart(2, '0');
402
- var defaultDate = `${year}年${month}月${date}日`;
403
- console.log(defaultDate, 'defaultDate');
404
- return defaultDate;
405
- }
406
-
407
- /** 根据数字获取几天内的日期
408
- * 数字为负 显示几天前
409
- * 数字为正 显示几天后
410
- * */
411
-
412
- export function getDay(day) {
413
- var today = new Date();
414
- var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
415
- today.setTime(targetday_milliseconds); //注意,这行是关键代码
416
- var tYear = today.getFullYear();
417
- var tMonth = today.getMonth();
418
- var tDate = today.getDate();
419
- tMonth = doHandleMonth(tMonth + 1);
420
- tDate = doHandleMonth(tDate);
421
- return tYear + '-' + tMonth + '-' + tDate;
422
- }
423
-
424
- function doHandleMonth(month) {
425
- var m = month;
426
- if (month.toString().length == 1) {
427
- m = '0' + month;
428
- }
429
- return m;
430
- }
431
-
432
- //获取随机uuid
433
- export function getuuid() {
434
- var s = [];
435
- var hexDigits = '0123456789abcdef';
436
- for (var i = 0; i < 36; i++) {
437
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
438
- }
439
- s[14] = '4';
440
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
441
- s[8] = s[13] = s[18] = s[23] = '-';
442
- return 'vf-' + s.join('');
443
- }
444
-
445
- // 文件流 转化 pdf或img url
446
- export function getObjectURL(file) {
447
- let url = null;
448
- if (window.createObjectURL !== undefined) {
449
- // basic
450
- url = window.createObjectURL(file);
451
- } else if (window.webkitURL !== undefined) {
452
- // webkit or chrome
453
- try {
454
- url = window.webkitURL.createObjectURL(file);
455
- } catch (error) {
456
- console.log(error);
457
- }
458
- } else if (window.URL !== undefined) {
459
- // mozilla(firefox)
460
- try {
461
- url = window.URL.createObjectURL(file);
462
- } catch (error) {
463
- console.log(error);
464
- }
465
- }
466
- return url;
467
- }
468
-
469
- // blob 转化 base64
470
- export function blobToBase64(blob) {
471
- return new Promise((resolve, reject) => {
472
- const fileReader = new FileReader();
473
- fileReader.onload = e => {
474
- resolve(e.target.result);
475
- };
476
- // readAsDataURL
477
- fileReader.readAsDataURL(blob);
478
- fileReader.onerror = () => {
479
- reject(new Error('文件流异常'));
480
- };
481
- });
482
- }
483
-
484
- /**数组根据数组对象中的某个属性值进行排序的方法
485
- * 使用例子:newArray.sort(sortBy('number',false)) //表示根据number属性降序排列;若第二个参数不传递,默认表示升序排序
486
- * @param attr 排序的属性 如number属性
487
- * @param rev true表示升序排列,false降序排序
488
- * */
489
- export function sortBy(attr, rev, key) {
490
- //第二个参数没有传递 默认升序排列
491
- if (rev == undefined) {
492
- rev = 1;
493
- } else {
494
- rev = rev ? 1 : -1;
495
- }
496
- console.log(key, 'key');
497
-
498
- return function (a, b) {
499
- a = a[attr];
500
- b = b[attr];
501
- if (key == 'date') {
502
- console.log(new Date(a), new Date(b), 11);
503
- if (new Date(a) < new Date(b)) {
504
- return rev * -1;
505
- }
506
- if (new Date(a) > new Date(b)) {
507
- return rev * 1;
508
- }
509
- return 0;
510
- } else {
511
- if (a < b) {
512
- return rev * -1;
513
- }
514
- if (a > b) {
515
- return rev * 1;
516
- }
517
- return 0;
518
- }
519
- };
520
- }
1
+ /**
2
+ * Created by PanJiaChen on 16/11/18.
3
+ */
4
+
5
+ /**
6
+ * Parse the time to string
7
+ * @param {(Object|string|number)} time
8
+ * @param {string} cFormat
9
+ * @returns {string}
10
+ */
11
+ export function parseTime(time, cFormat) {
12
+ if (!time) return '';
13
+ if (arguments.length === 0) {
14
+ return null;
15
+ }
16
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}';
17
+ let date;
18
+ if (typeof time === 'undefined' || time === null || time === 'null') {
19
+ return '';
20
+ } else if (typeof time === 'object') {
21
+ date = time;
22
+ } else {
23
+ if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
24
+ time = parseInt(time);
25
+ }
26
+ if (typeof time === 'number' && time.toString().length === 10) {
27
+ time = time * 1000;
28
+ }
29
+ date = new Date(time);
30
+ }
31
+ const formatObj = {
32
+ y: date.getFullYear(),
33
+ m: date.getMonth() + 1,
34
+ d: date.getDate(),
35
+ h: date.getHours(),
36
+ i: date.getMinutes(),
37
+ s: date.getSeconds(),
38
+ a: date.getDay(),
39
+ };
40
+ const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
41
+ let value = formatObj[key];
42
+ // Note: getDay() returns 0 on Sunday
43
+ if (key === 'a') {
44
+ return ['日', '一', '二', '三', '四', '五', '六'][value];
45
+ }
46
+ if (result.length > 0 && value < 10) {
47
+ value = '0' + value;
48
+ }
49
+ return value || 0;
50
+ });
51
+ return time_str;
52
+ }
53
+
54
+ /**
55
+ * @param {number} time
56
+ * @param {string} option
57
+ * @returns {string}
58
+ */
59
+ export function formatTime(time, option) {
60
+ if (('' + time).length === 10) {
61
+ time = parseInt(time) * 1000;
62
+ } else {
63
+ time = +time;
64
+ }
65
+ const d = new Date(time);
66
+ const now = Date.now();
67
+
68
+ const diff = (now - d) / 1000;
69
+
70
+ if (diff < 30) {
71
+ return '刚刚';
72
+ } else if (diff < 3600) {
73
+ // less 1 hour
74
+ return Math.ceil(diff / 60) + '分钟前';
75
+ } else if (diff < 3600 * 24) {
76
+ return Math.ceil(diff / 3600) + '小时前';
77
+ } else if (diff < 3600 * 24 * 2) {
78
+ return '1天前';
79
+ }
80
+ if (option) {
81
+ return parseTime(time, option);
82
+ } else {
83
+ return (
84
+ d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
85
+ );
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @param {string} url
91
+ * @returns {Object}
92
+ */
93
+ export function getQueryObject(url) {
94
+ url = url == null ? window.location.href : url;
95
+ const search = url.substring(url.lastIndexOf('?') + 1);
96
+ const obj = {};
97
+ const reg = /([^?&=]+)=([^?&=]*)/g;
98
+ search.replace(reg, (rs, $1, $2) => {
99
+ const name = decodeURIComponent($1);
100
+ let val = decodeURIComponent($2);
101
+ val = String(val);
102
+ obj[name] = val;
103
+ return rs;
104
+ });
105
+ return obj;
106
+ }
107
+
108
+ /**
109
+ * @param {string} input value
110
+ * @returns {number} output value
111
+ */
112
+ export function byteLength(str) {
113
+ // returns the byte length of an utf8 string
114
+ let s = str.length;
115
+ for (var i = str.length - 1; i >= 0; i--) {
116
+ const code = str.charCodeAt(i);
117
+ if (code > 0x7f && code <= 0x7ff) s++;
118
+ else if (code > 0x7ff && code <= 0xffff) s += 2;
119
+ if (code >= 0xdc00 && code <= 0xdfff) i--;
120
+ }
121
+ return s;
122
+ }
123
+
124
+ /**
125
+ * @param {Array} actual
126
+ * @returns {Array}
127
+ */
128
+ export function cleanArray(actual) {
129
+ const newArray = [];
130
+ for (let i = 0; i < actual.length; i++) {
131
+ if (actual[i]) {
132
+ newArray.push(actual[i]);
133
+ }
134
+ }
135
+ return newArray;
136
+ }
137
+
138
+ /**
139
+ * @param {Object} json
140
+ * @returns {Array}
141
+ */
142
+ export function param(json) {
143
+ if (!json) return '';
144
+ return cleanArray(
145
+ Object.keys(json).map(key => {
146
+ if (json[key] === undefined) return '';
147
+ return encodeURIComponent(key) + '=' + encodeURIComponent(json[key]);
148
+ })
149
+ ).join('&');
150
+ }
151
+
152
+ /**
153
+ * @param {string} url
154
+ * @returns {Object}
155
+ */
156
+ export function param2Obj(url) {
157
+ const search = url.split('?')[1];
158
+ if (!search) {
159
+ return {};
160
+ }
161
+ return JSON.parse(
162
+ '{"' +
163
+ decodeURIComponent(search)
164
+ .replace(/"/g, '\\"')
165
+ .replace(/&/g, '","')
166
+ .replace(/=/g, '":"')
167
+ .replace(/\+/g, ' ') +
168
+ '"}'
169
+ );
170
+ }
171
+
172
+ /**
173
+ * @param {string} val
174
+ * @returns {string}
175
+ */
176
+ export function html2Text(val) {
177
+ const div = document.createElement('div');
178
+ div.innerHTML = val;
179
+ return div.textContent || div.innerText;
180
+ }
181
+
182
+ /**
183
+ * Merges two objects, giving the last one precedence
184
+ * @param {Object} target
185
+ * @param {(Object|Array)} source
186
+ * @returns {Object}
187
+ */
188
+ export function objectMerge(target, source) {
189
+ if (typeof target !== 'object') {
190
+ target = {};
191
+ }
192
+ if (Array.isArray(source)) {
193
+ return source.slice();
194
+ }
195
+ Object.keys(source).forEach(property => {
196
+ const sourceProperty = source[property];
197
+ if (typeof sourceProperty === 'object') {
198
+ target[property] = objectMerge(target[property], sourceProperty);
199
+ } else {
200
+ target[property] = sourceProperty;
201
+ }
202
+ });
203
+ return target;
204
+ }
205
+
206
+ /**
207
+ * @param {HTMLElement} element
208
+ * @param {string} className
209
+ */
210
+ export function toggleClass(element, className) {
211
+ if (!element || !className) {
212
+ return;
213
+ }
214
+ let classString = element.className;
215
+ const nameIndex = classString.indexOf(className);
216
+ if (nameIndex === -1) {
217
+ classString += '' + className;
218
+ } else {
219
+ classString =
220
+ classString.substr(0, nameIndex) + classString.substr(nameIndex + className.length);
221
+ }
222
+ element.className = classString;
223
+ }
224
+
225
+ /**
226
+ * @param {string} type
227
+ * @returns {Date}
228
+ */
229
+ export function getTime(type) {
230
+ if (type === 'start') {
231
+ return new Date().getTime() - 3600 * 1000 * 24 * 90;
232
+ } else {
233
+ return new Date(new Date().toDateString());
234
+ }
235
+ }
236
+
237
+ /**
238
+ * @param {Function} func
239
+ * @param {number} wait
240
+ * @param {boolean} immediate
241
+ * @return {*}
242
+ */
243
+ export function debounce(func, wait, immediate) {
244
+ let timeout, args, context, timestamp, result;
245
+
246
+ const later = function () {
247
+ // 据上一次触发时间间隔
248
+ const last = +new Date() - timestamp;
249
+
250
+ // 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
251
+ if (last < wait && last > 0) {
252
+ timeout = setTimeout(later, wait - last);
253
+ } else {
254
+ timeout = null;
255
+ // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
256
+ if (!immediate) {
257
+ result = func.apply(context, args);
258
+ if (!timeout) context = args = null;
259
+ }
260
+ }
261
+ };
262
+
263
+ return function (...args) {
264
+ context = this;
265
+ timestamp = +new Date();
266
+ const callNow = immediate && !timeout;
267
+ // 如果延时不存在,重新设定延时
268
+ if (!timeout) timeout = setTimeout(later, wait);
269
+ if (callNow) {
270
+ result = func.apply(context, args);
271
+ context = args = null;
272
+ }
273
+
274
+ return result;
275
+ };
276
+ }
277
+
278
+ /**
279
+ * This is just a simple version of deep copy
280
+ * Has a lot of edge cases bug
281
+ * If you want to use a perfect deep copy, use lodash's _.cloneDeep
282
+ * @param {Object} source
283
+ * @returns {Object}
284
+ */
285
+ export function deepClone(source) {
286
+ if (!source && typeof source !== 'object') {
287
+ throw new Error('error arguments', 'deepClone');
288
+ }
289
+ const targetObj = source.constructor === Array ? [] : {};
290
+ Object.keys(source).forEach(keys => {
291
+ if (source[keys] && typeof source[keys] === 'object') {
292
+ targetObj[keys] = deepClone(source[keys]);
293
+ } else {
294
+ targetObj[keys] = source[keys];
295
+ }
296
+ });
297
+ return targetObj;
298
+ }
299
+
300
+ /**
301
+ * @param {Array} arr
302
+ * @returns {Array}
303
+ */
304
+ export function uniqueArr(arr) {
305
+ return Array.from(new Set(arr));
306
+ }
307
+
308
+ /**
309
+ * @returns {string}
310
+ */
311
+ export function createUniqueString() {
312
+ const timestamp = +new Date() + '';
313
+ const randomNum = parseInt((1 + Math.random()) * 65536) + '';
314
+ return (+(randomNum + timestamp)).toString(32);
315
+ }
316
+
317
+ /**
318
+ * Check if an element has a class
319
+ * @param {HTMLElement} elm
320
+ * @param {string} cls
321
+ * @returns {boolean}
322
+ */
323
+ export function hasClass(ele, cls) {
324
+ return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
325
+ }
326
+
327
+ /**
328
+ * Add class to element
329
+ * @param {HTMLElement} elm
330
+ * @param {string} cls
331
+ */
332
+ export function addClass(ele, cls) {
333
+ if (!hasClass(ele, cls)) ele.className += ' ' + cls;
334
+ }
335
+
336
+ /**
337
+ * Remove class from element
338
+ * @param {HTMLElement} elm
339
+ * @param {string} cls
340
+ */
341
+ export function removeClass(ele, cls) {
342
+ if (hasClass(ele, cls)) {
343
+ const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
344
+ ele.className = ele.className.replace(reg, ' ');
345
+ }
346
+ }
347
+
348
+ // 替换邮箱字符
349
+ export function regEmail(email) {
350
+ if (String(email).indexOf('@') > 0) {
351
+ const str = email.split('@');
352
+ let _s = '';
353
+ if (str[0].length > 3) {
354
+ for (var i = 0; i < str[0].length - 3; i++) {
355
+ _s += '*';
356
+ }
357
+ }
358
+ var new_email = str[0].substr(0, 3) + _s + '@' + str[1];
359
+ }
360
+ return new_email;
361
+ }
362
+
363
+ // 替换手机字符
364
+ export function regMobile(mobile) {
365
+ if (mobile.length > 7) {
366
+ var new_mobile = mobile.substr(0, 3) + '****' + mobile.substr(7);
367
+ }
368
+ return new_mobile;
369
+ }
370
+
371
+ // 下载文件
372
+ export function downloadFile(obj, name, suffix, isCn) {
373
+ const url = window.URL.createObjectURL(new Blob([obj]));
374
+ const link = document.createElement('a');
375
+ link.style.display = 'none';
376
+ link.href = url;
377
+ let fileName = null;
378
+ console.log(isCn, 'isCn');
379
+ if (typeof isCn === 'boolean') {
380
+ if (isCn) {
381
+ fileName = name + getCNDate() + '.' + suffix;
382
+ } else if (!isCn) {
383
+ fileName = name + '.' + suffix;
384
+ }
385
+ } else {
386
+ fileName = name + '-' + parseTime(new Date()) + '.' + suffix;
387
+ }
388
+
389
+ link.setAttribute('download', fileName);
390
+ document.body.appendChild(link);
391
+ link.click();
392
+ document.body.removeChild(link);
393
+ }
394
+ export function getCNDate() {
395
+ var now = new Date();
396
+ var year = now.getFullYear(); // 得到年份
397
+ var month = now.getMonth(); // 得到月份
398
+ var date = now.getDate(); // 得到日期
399
+ month = month + 1;
400
+ month = month.toString().padStart(2, '0');
401
+ date = date.toString().padStart(2, '0');
402
+ var defaultDate = `${year}年${month}月${date}日`;
403
+ console.log(defaultDate, 'defaultDate');
404
+ return defaultDate;
405
+ }
406
+
407
+ /** 根据数字获取几天内的日期
408
+ * 数字为负 显示几天前
409
+ * 数字为正 显示几天后
410
+ * */
411
+
412
+ export function getDay(day) {
413
+ var today = new Date();
414
+ var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
415
+ today.setTime(targetday_milliseconds); //注意,这行是关键代码
416
+ var tYear = today.getFullYear();
417
+ var tMonth = today.getMonth();
418
+ var tDate = today.getDate();
419
+ tMonth = doHandleMonth(tMonth + 1);
420
+ tDate = doHandleMonth(tDate);
421
+ return tYear + '-' + tMonth + '-' + tDate;
422
+ }
423
+
424
+ function doHandleMonth(month) {
425
+ var m = month;
426
+ if (month.toString().length == 1) {
427
+ m = '0' + month;
428
+ }
429
+ return m;
430
+ }
431
+
432
+ //获取随机uuid
433
+ export function getuuid() {
434
+ var s = [];
435
+ var hexDigits = '0123456789abcdef';
436
+ for (var i = 0; i < 36; i++) {
437
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
438
+ }
439
+ s[14] = '4';
440
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
441
+ s[8] = s[13] = s[18] = s[23] = '-';
442
+ return 'vf-' + s.join('');
443
+ }
444
+
445
+ // 文件流 转化 pdf或img url
446
+ export function getObjectURL(file) {
447
+ let url = null;
448
+ if (window.createObjectURL !== undefined) {
449
+ // basic
450
+ url = window.createObjectURL(file);
451
+ } else if (window.webkitURL !== undefined) {
452
+ // webkit or chrome
453
+ try {
454
+ url = window.webkitURL.createObjectURL(file);
455
+ } catch (error) {
456
+ console.log(error);
457
+ }
458
+ } else if (window.URL !== undefined) {
459
+ // mozilla(firefox)
460
+ try {
461
+ url = window.URL.createObjectURL(file);
462
+ } catch (error) {
463
+ console.log(error);
464
+ }
465
+ }
466
+ return url;
467
+ }
468
+
469
+ // blob 转化 base64
470
+ export function blobToBase64(blob) {
471
+ return new Promise((resolve, reject) => {
472
+ const fileReader = new FileReader();
473
+ fileReader.onload = e => {
474
+ resolve(e.target.result);
475
+ };
476
+ // readAsDataURL
477
+ fileReader.readAsDataURL(blob);
478
+ fileReader.onerror = () => {
479
+ reject(new Error('文件流异常'));
480
+ };
481
+ });
482
+ }
483
+
484
+ /**数组根据数组对象中的某个属性值进行排序的方法
485
+ * 使用例子:newArray.sort(sortBy('number',false)) //表示根据number属性降序排列;若第二个参数不传递,默认表示升序排序
486
+ * @param attr 排序的属性 如number属性
487
+ * @param rev true表示升序排列,false降序排序
488
+ * */
489
+ export function sortBy(attr, rev, key) {
490
+ //第二个参数没有传递 默认升序排列
491
+ if (rev == undefined) {
492
+ rev = 1;
493
+ } else {
494
+ rev = rev ? 1 : -1;
495
+ }
496
+ console.log(key, 'key');
497
+
498
+ return function (a, b) {
499
+ a = a[attr];
500
+ b = b[attr];
501
+ if (key == 'date') {
502
+ console.log(new Date(a), new Date(b), 11);
503
+ if (new Date(a) < new Date(b)) {
504
+ return rev * -1;
505
+ }
506
+ if (new Date(a) > new Date(b)) {
507
+ return rev * 1;
508
+ }
509
+ return 0;
510
+ } else {
511
+ if (a < b) {
512
+ return rev * -1;
513
+ }
514
+ if (a > b) {
515
+ return rev * 1;
516
+ }
517
+ return 0;
518
+ }
519
+ };
520
+ }