ipadStatic.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="app-container">
  3. <el-card>
  4. <div slot="header" class="clearfix">
  5. <span>设备绑定统计</span>
  6. </div>
  7. <el-tabs v-model="activeTab" @tab-click="handleTabClick">
  8. <el-tab-pane label="按天统计" name="daily">
  9. <el-form :inline="true" class="demo-form-inline">
  10. <el-form-item label="日期">
  11. <el-date-picker
  12. v-model="dailyDate"
  13. type="date"
  14. placeholder="选择日期"
  15. value-format="yyyy-MM-dd"
  16. @change="handleDailyDateChange"
  17. ></el-date-picker>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click="searchDaily">查询</el-button>
  21. <el-button @click="resetDaily">重置</el-button>
  22. <el-button type="success" @click="exportDaily">导出</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-table
  26. v-loading="dailyLoading"
  27. border
  28. :data="companyList"
  29. style="width: 100%"
  30. >
  31. <el-table-column prop="date" label="日期" width="180" />
  32. <el-table-column prop="companyName" label="公司名称" />
  33. <el-table-column prop="bindCount" label="绑定台数" />
  34. </el-table>
  35. <div class="chart-container" style="margin-top: 20px; height: 400px">
  36. <div ref="dailyChart" style="height: 100%; width: 100%"></div>
  37. </div>
  38. </el-tab-pane>
  39. <el-tab-pane label="按月统计" name="monthly">
  40. <el-form :inline="true" class="demo-form-inline">
  41. <el-form-item label="月份">
  42. <el-date-picker
  43. v-model="monthlyDate"
  44. type="month"
  45. placeholder="选择月份"
  46. value-format="yyyy-MM"
  47. @change="handleMonthlyDateChange"
  48. ></el-date-picker>
  49. </el-form-item>
  50. <el-form-item>
  51. <el-button type="primary" @click="searchMonthly">查询</el-button>
  52. <el-button @click="resetMonthly">重置</el-button>
  53. <el-button type="success" @click="exportMonthly">导出</el-button>
  54. </el-form-item>
  55. </el-form>
  56. <el-table
  57. v-loading="monthlyLoading"
  58. border
  59. :data="companyList"
  60. style="width: 100%"
  61. >
  62. <el-table-column prop="date" label="月份" width="180" />
  63. <el-table-column prop="companyName" label="公司名称" />
  64. <el-table-column prop="bindCount" label="绑定台数" />
  65. </el-table>
  66. <div class="chart-container" style="margin-top: 20px; height: 400px">
  67. <div ref="monthlyChart" style="height: 100%; width: 100%"></div>
  68. </div>
  69. </el-tab-pane>
  70. </el-tabs>
  71. </el-card>
  72. </div>
  73. </template>
  74. <script>
  75. import { ipadStaticTotal,exportIpadStaticByTime} from "@/api/company/statistics";
  76. export default {
  77. name: 'ipadStatic',
  78. data() {
  79. const today = this.parseTime(new Date(), '{y}-{m}-{d}')
  80. const yesterday = this.parseTime(new Date(new Date().getTime() - 24 * 60 * 60 * 1000), '{y}-{m}-{d}')
  81. return {
  82. // 激活的标签页
  83. activeTab: 'daily',
  84. // 按天统计数据
  85. dailyLoading: false,
  86. dailyDate: yesterday, // 默认当天
  87. // 按月统计数据
  88. monthlyLoading: false,
  89. monthlyDate: this.parseTime(new Date(), '{y}-{m}'), // 默认当月
  90. companyList: [],
  91. }
  92. },
  93. created() {
  94. // 获取当天数据
  95. this.getList()
  96. },
  97. methods: {
  98. // 标签页切换
  99. handleTabClick(tab) {
  100. if (tab.name === 'daily') {
  101. this.getList()
  102. } else if (tab.name === 'monthly') {
  103. this.getMonthlyList()
  104. }
  105. },
  106. // 按天统计相关方法
  107. handleDailyDateChange(val) {
  108. if (val) {
  109. this.dailyDate = val
  110. }
  111. },
  112. searchDaily() {
  113. this.getList()
  114. },
  115. resetDaily() {
  116. const today = this.parseTime(new Date(), '{y}-{m}-{d}')
  117. const yesterday = this.parseTime(new Date(new Date().getTime() - 24 * 60 * 60 * 1000), '{y}-{m}-{d}')
  118. this.dailyDate = yesterday
  119. this.getList()
  120. },
  121. // 导出
  122. exportDaily() {
  123. this.$confirm("是否确认导出数据项?", "警告", {
  124. confirmButtonText: "确定",
  125. cancelButtonText: "取消",
  126. type: "warning",
  127. })
  128. .then(() => {
  129. this.exportLoading = true;
  130. return exportIpadStaticByTime(this.dailyDate);
  131. })
  132. .then((response) => {
  133. this.download(response.msg);
  134. this.exportLoading = false;
  135. })
  136. .catch(() => { });
  137. },
  138. getList() {
  139. this.dailyLoading = true
  140. ipadStaticTotal(this.dailyDate).then(response => {
  141. // 处理返回数据,添加日期字段用于表格和图表显示
  142. this.companyList = response.list;
  143. this.dailyLoading = false;
  144. }).catch(() => {
  145. this.dailyLoading = false;
  146. });
  147. },
  148. // 按月统计相关方法
  149. handleMonthlyDateChange(val) {
  150. if (val) {
  151. this.monthlyDate = val
  152. }
  153. },
  154. searchMonthly() {
  155. this.getMonthlyList()
  156. },
  157. resetMonthly() {
  158. this.monthlyDate = this.parseTime(new Date(), '{y}-{m}')
  159. this.getMonthlyList()
  160. },
  161. exportMonthly() {
  162. this.$confirm("是否确认导出数据项?", "警告", {
  163. confirmButtonText: "确定",
  164. cancelButtonText: "取消",
  165. type: "warning",
  166. })
  167. .then(() => {
  168. this.exportLoading = true;
  169. return exportIpadStaticByTime(this.monthlyDate);
  170. })
  171. .then((response) => {
  172. this.download(response.msg);
  173. this.exportLoading = false;
  174. })
  175. .catch(() => { });
  176. },
  177. getMonthlyList() {
  178. this.monthlyLoading = true
  179. ipadStaticTotal(this.monthlyDate).then(response => {
  180. // 处理返回数据,添加月份字段用于表格和图表显示
  181. this.companyList = response.list;
  182. this.monthlyLoading = false;
  183. }).catch(() => {
  184. this.monthlyLoading = false;
  185. this.monthlyTotal = 0;
  186. });
  187. },
  188. // 日期格式化
  189. parseTime(time, pattern) {
  190. let date;
  191. if (arguments.length === 0 || !time) {
  192. return null
  193. }
  194. const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
  195. if (typeof time === 'object') {
  196. date = time
  197. } else {
  198. if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
  199. time = parseInt(time)
  200. } else if (typeof time === 'string') {
  201. time = time.replace(new RegExp(/-/gm), '/')
  202. }
  203. if ((typeof time === 'number') && (time.toString().length === 10)) {
  204. time = time * 1000
  205. }
  206. date = new Date(time)
  207. }
  208. const formatObj = {
  209. y: date.getFullYear(),
  210. m: date.getMonth() + 1,
  211. d: date.getDate(),
  212. h: date.getHours(),
  213. i: date.getMinutes(),
  214. s: date.getSeconds(),
  215. a: date.getDay()
  216. }
  217. const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
  218. let value = formatObj[key]
  219. // Note: getDay() returns 0 on Sunday
  220. if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
  221. if (result.length > 0 && value < 10) {
  222. value = '0' + value
  223. }
  224. return value || 0
  225. })
  226. return time_str
  227. }
  228. }
  229. }
  230. </script>
  231. <style scoped>
  232. .chart-container {
  233. position: relative;
  234. padding: 20px 0;
  235. }
  236. </style>