|
|
@@ -10,48 +10,7 @@
|
|
|
</ElCol>
|
|
|
</ElRow>
|
|
|
</ElConfigProvider>
|
|
|
- <ElDialog v-model="showCreateTaskDialog" title="新建任务" width="500px">
|
|
|
- <ElForm
|
|
|
- :model="createTaskForm"
|
|
|
- :rules="createTaskRule"
|
|
|
- ref="createTaskFormRef"
|
|
|
- label-position="right"
|
|
|
- label-width="100px"
|
|
|
- >
|
|
|
- <ElFormItem prop="type" label="任务类型">
|
|
|
- <ElSelect v-model="createTaskForm.type">
|
|
|
- <ElOption v-for="key in TaskType" :key="key" :label="TaskType[key]" :value="key"></ElOption>
|
|
|
- </ElSelect>
|
|
|
- </ElFormItem>
|
|
|
- <ElFormItem
|
|
|
- prop="amount"
|
|
|
- label="金额"
|
|
|
- v-if="!(createTaskForm.type === 'mint' || createTaskForm.type === 'removeLiquidity')"
|
|
|
- >
|
|
|
- <ElInputNumber v-model="createTaskForm.minAmount" class="mr-3 !w-24" :controls="false" />
|
|
|
- ~
|
|
|
- <ElInputNumber v-model="createTaskForm.maxAmount" class="ml-3 mr-4 !w-24" :controls="false" />
|
|
|
- </ElFormItem>
|
|
|
- <ElFormItem prop="startTime" label="执行时间">
|
|
|
- <ElDatePicker type="datetime" v-model="createTaskForm.startTime"></ElDatePicker>
|
|
|
- </ElFormItem>
|
|
|
- <ElFormItem prop="interval" label="间隔时间">
|
|
|
- <ElInputNumber v-model="createTaskForm.minInterval" :min="1" class="mr-3 !w-24" :controls="false" />
|
|
|
- ~
|
|
|
- <ElInputNumber
|
|
|
- v-model="createTaskForm.maxInterval"
|
|
|
- :min="1"
|
|
|
- class="ml-3 mr-3 !w-24"
|
|
|
- :controls="false"
|
|
|
- />
|
|
|
- 秒
|
|
|
- </ElFormItem>
|
|
|
- </ElForm>
|
|
|
- <template #footer>
|
|
|
- <ElButton @click="showCreateTaskDialog = false">取消</ElButton>
|
|
|
- <ElButton type="primary" @click="createTask" :loading="creatingTask">确定</ElButton>
|
|
|
- </template>
|
|
|
- </ElDialog>
|
|
|
+ <CreateTask v-model="showCreateTask" :accounts="selectedAccounts" />
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
@@ -62,85 +21,19 @@ import { TaskType } from '@/enums'
|
|
|
import AccountsView from './AccountsView.vue'
|
|
|
import TaskView from '@/views/TaskView.vue'
|
|
|
import LogsView from './LogsView.vue'
|
|
|
+import CreateTask from './CreateTask.vue'
|
|
|
|
|
|
const accountsView = ref(null)
|
|
|
function selected() {
|
|
|
return accountsView.value && accountsView.value.selected()
|
|
|
}
|
|
|
-
|
|
|
-const showCreateTaskDialog = ref(false)
|
|
|
-const createTaskFormRef = ref(null)
|
|
|
-const createTaskForm = ref({})
|
|
|
-const createTaskRule = {
|
|
|
- type: [{ required: true, message: '请选择类型' }],
|
|
|
- amount: [
|
|
|
- {
|
|
|
- validator: (rule, value, callback) => {
|
|
|
- if (createTaskForm.value.type !== 'min') {
|
|
|
- if (!(createTaskForm.value.minAmount && createTaskForm.value.maxAmount)) {
|
|
|
- callback(new Error('请输入金额'))
|
|
|
- } else if (Number(createTaskForm.value.minAmount) > Number(createTaskForm.value.maxAmount)) {
|
|
|
- callback(new Error('最小金额不能大于最大金额'))
|
|
|
- } else {
|
|
|
- callback()
|
|
|
- }
|
|
|
- } else {
|
|
|
- callback()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ],
|
|
|
- startTime: [{ required: true, message: '请选择执行时间' }],
|
|
|
- interval: [
|
|
|
- {
|
|
|
- validator: (rule, value, callback) => {
|
|
|
- if (!(createTaskForm.value.minInterval && createTaskForm.value.maxInterval)) {
|
|
|
- callback(new Error('请输入间隔时间'))
|
|
|
- } else if (Number(createTaskForm.value.minInterval) > Number(createTaskForm.value.maxInterval)) {
|
|
|
- callback(new Error('最小间隔时间不能大于最大间隔时间'))
|
|
|
- } else {
|
|
|
- callback()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
-}
|
|
|
-const creatingTask = ref(false)
|
|
|
+const showCreateTask = ref(false)
|
|
|
+const selectedAccounts = ref([])
|
|
|
function onCreateTask() {
|
|
|
- if (selected().length === 0) {
|
|
|
- ElMessage.warning('请先选择账号')
|
|
|
- return
|
|
|
+ selectedAccounts.value = selected()
|
|
|
+ if (selectedAccounts.value.length === 0) {
|
|
|
+ return ElMessage.warning('请选择账号')
|
|
|
}
|
|
|
- createTaskForm.value = {}
|
|
|
- if (createTaskFormRef.value) {
|
|
|
- createTaskFormRef.value.clearValidate()
|
|
|
- }
|
|
|
- showCreateTaskDialog.value = true
|
|
|
-}
|
|
|
-function createTask() {
|
|
|
- createTaskFormRef.value.validate(async (valid) => {
|
|
|
- if (valid) {
|
|
|
- creatingTask.value = true
|
|
|
- try {
|
|
|
- await http.put('/tasks', {
|
|
|
- accounts: selected().map((i) => i.id),
|
|
|
- params: {
|
|
|
- minAmount: createTaskForm.value.minAmount,
|
|
|
- maxAmount: createTaskForm.value.maxAmount,
|
|
|
- minInterval: createTaskForm.value.minInterval,
|
|
|
- maxInterval: createTaskForm.value.maxInterval
|
|
|
- },
|
|
|
- type: createTaskForm.value.type,
|
|
|
- startTime: createTaskForm.value.startTime
|
|
|
- })
|
|
|
- ElMessage.success('任务添加成功')
|
|
|
- creatingTask.value = false
|
|
|
- showCreateTaskDialog.value = false
|
|
|
- } catch (error) {
|
|
|
- creatingTask.value = false
|
|
|
- ElMessage.error(error.message)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ showCreateTask.value = true
|
|
|
}
|
|
|
</script>
|