Casper Dai 2 лет назад
Родитель
Сommit
1e97425450

+ 5 - 0
src/router/index.js

@@ -421,6 +421,11 @@ export const asyncRoutes = [
     access: Access.MANAGE_TENANTS,
     meta: { title: '超管功能', icon: 'pm' },
     children: [
+      {
+        path: 'settings',
+        component: () => import('@/views/platform/settings/index'),
+        meta: { title: '功能管理' }
+      },
       {
         path: 'tenant',
         component: () => import('@/views/platform/tenant/index'),

+ 55 - 0
src/views/platform/settings/api.js

@@ -0,0 +1,55 @@
+import request from '@/utils/request'
+import {
+  update,
+  send
+} from '@/api/base'
+
+export function getTimeTask (functionKey) {
+  return send({
+    url: '/device/functionTask',
+    method: 'GET',
+    params: {
+      deviceId: 1000,
+      functionKey
+    }
+  }).then(({ data }) => {
+    return { data: data[0] }
+  })
+}
+
+export function addTimeTask (task) {
+  return update({
+    url: '/device/functionTask',
+    method: 'POST',
+    data: {
+      deviceId: 1000,
+      ...task
+    }
+  })
+}
+
+export function updateTimeTask (task) {
+  return update({
+    url: '/device/functionTask',
+    method: 'PUT',
+    data: {
+      deviceId: 1000,
+      ...task
+    }
+  })
+}
+
+export function getTaskHistory (query) {
+  const { pageNum: pageIndex, pageSize, ...params } = query
+  return request({
+    url: '/device/listInvokeHistory',
+    method: 'POST',
+    data: {
+      pageIndex,
+      pageSize,
+      param: {
+        ...params
+      }
+    }
+  })
+}

+ 112 - 0
src/views/platform/settings/components/TimeTaskDialog.vue

@@ -0,0 +1,112 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="定时任务"
+    size="fixed"
+    @confirm="onSave"
+  >
+    <template #default>
+      <div class="l-flex--row c-sibling-item--v">
+        <span class="c-sibling-item">启用</span>
+        <el-switch
+          v-model="config.status"
+          class="c-sibling-item"
+          :active-value="1"
+          :inactive-value="0"
+          active-color="#13ce66"
+          inactive-color="#ff4949"
+        />
+        <span class="c-sibling-item farther u-required">触发时间</span>
+        <el-time-picker
+          v-model="config.executeTime"
+          class="c-sibling-item"
+          placeholder="请选择触发时间"
+          value-format="HH:mm:ss"
+          :clearable="false"
+        />
+      </div>
+      <schema-table
+        class="c-sibling-item--v"
+        :schema="schema"
+      />
+    </template>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  getTimeTask,
+  updateTimeTask,
+  addTimeTask,
+  getTaskHistory
+} from '../api'
+
+export default {
+  name: 'TimeTaskDialog',
+  data () {
+    return {
+      config: {
+        status: false,
+        executeTime: '00:00:00'
+      },
+      schema: {
+        list: getTaskHistory,
+        condition: { functionKey: '' },
+        cols: [
+          { type: 'refresh' },
+          { prop: 'executeTime', label: '触发时间' },
+          { label: '结果', type: 'tag', render: ({ status }) => {
+            return {
+              type: ['primary', 'success', 'danger'][status],
+              label: ['未知', '成功', '失败'][status]
+            }
+          } }
+        ]
+      }
+    }
+  },
+  methods: {
+    show (functionKey) {
+      getTimeTask(functionKey).then(({ data }) => {
+        this.schema.condition.functionKey = functionKey
+        if (data) {
+          const { taskId, executeTime, status } = data
+          this.config = {
+            taskId,
+            status,
+            executeTime,
+            freq: 0
+          }
+        } else {
+          this.config = {
+            functionKey,
+            status: 0,
+            freq: 0,
+            executeTime: '00:00:00'
+          }
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      const { status, executeTime } = this.config
+      if (status && !executeTime) {
+        this.$message({
+          type: 'warning',
+          message: '请选择触发时间'
+        })
+        return
+      }
+      if (this.config.taskId) {
+        updateTimeTask({
+          ...this.config
+        }).then(done)
+      } else {
+        addTimeTask({
+          ...this.config
+        }).then(done)
+      }
+    }
+  }
+}
+</script>

+ 44 - 0
src/views/platform/settings/index.vue

@@ -0,0 +1,44 @@
+<template>
+  <wrapper
+    fill
+    margin
+    padding
+    background
+  >
+    <span class="c-sibling-item--v u-font-size--sm u-bold">定时任务</span>
+    <div class="c-sibling-item--v l-grid--info mini">
+      <button
+        class="o-button"
+        @click="onOnlineDurationTask"
+      >
+        在线时长统计
+      </button>
+      <button
+        class="o-button"
+        @click="onAdTask"
+      >
+        自助广告统计
+      </button>
+    </div>
+    <time-task-dialog ref="timeTaskDialog" />
+  </wrapper>
+</template>
+
+<script>
+import TimeTaskDialog from './components/TimeTaskDialog.vue'
+
+export default {
+  name: 'PlatformSettings',
+  components: {
+    TimeTaskDialog
+  },
+  methods: {
+    onOnlineDurationTask () {
+      this.$refs.timeTaskDialog.show('device_online_summary')
+    },
+    onAdTask () {
+      this.$refs.timeTaskDialog.show('advertisement_statistic')
+    }
+  }
+}
+</script>