feat: 添加现货机器人管理功能,更新相关路由和国际化配置,新增编辑组件

This commit is contained in:
2026-01-14 20:06:13 +07:00
parent 3569cbdf47
commit 84c4f08dc2
11 changed files with 426 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
# backend service base url, test environment
VITE_SERVICE_BASE_URL=http://192.168.1.7:9528
VITE_SERVICE_BASE_URL=https://riwa-api.riwsan1.com
# other backend service base url, test environment
VITE_OTHER_SERVICE_BASE_URL= `{}`

View File

@@ -36,6 +36,7 @@
"cleanup": "sa cleanup",
"commit": "sa git-commit",
"commit:zh": "sa git-commit -l=zh-cn",
"deploy:cloudflare": "wrangler pages deploy dist --project-name=riwa-admin --branch=main",
"dev": "vite --mode test",
"dev:prod": "vite --mode prod",
"gen-route": "sa gen-route",
@@ -50,7 +51,7 @@
"@better-scroll/core": "2.5.1",
"@elysiajs/eden": "^1.4.5",
"@iconify/vue": "5.0.0",
"@riwa/api-types": "http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz",
"@riwa/api-types": "http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz",
"@sa/axios": "workspace:*",
"@sa/color": "workspace:*",
"@sa/hooks": "workspace:*",

12
pnpm-lock.yaml generated
View File

@@ -18,8 +18,8 @@ importers:
specifier: 5.0.0
version: 5.0.0(vue@3.5.25(typescript@5.9.3))
'@riwa/api-types':
specifier: http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz
version: '@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz(@elysiajs/eden@1.4.5(elysia@1.4.19(@sinclair/typebox@0.34.41)(exact-mirror@0.2.5(@sinclair/typebox@0.34.41))(file-type@21.1.1)(openapi-types@12.1.3)(typescript@5.9.3)))'
specifier: http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz
version: '@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz(@elysiajs/eden@1.4.5(elysia@1.4.19(@sinclair/typebox@0.34.41)(exact-mirror@0.2.5(@sinclair/typebox@0.34.41))(file-type@21.1.1)(openapi-types@12.1.3)(typescript@5.9.3)))'
'@sa/axios':
specifier: workspace:*
version: link:packages/axios
@@ -1230,9 +1230,9 @@ packages:
'@quansync/fs@0.1.6':
resolution: {integrity: sha512-zoA8SqQO11qH9H8FCBR7NIbowYARIPmBz3nKjgAaOUDi/xPAAu1uAgebtV7KXHTc6CDZJVRZ1u4wIGvY5CWYaw==}
'@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz':
resolution: {tarball: http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz}
version: 0.0.135
'@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz':
resolution: {tarball: http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz}
version: 0.0.143
peerDependencies:
'@elysiajs/eden': ^1.4.5
@@ -5651,7 +5651,7 @@ snapshots:
dependencies:
quansync: 0.3.0
'@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.135.tgz(@elysiajs/eden@1.4.5(elysia@1.4.19(@sinclair/typebox@0.34.41)(exact-mirror@0.2.5(@sinclair/typebox@0.34.41))(file-type@21.1.1)(openapi-types@12.1.3)(typescript@5.9.3)))':
'@riwa/eden@http://192.168.1.7:9528/api/riwa-eden-0.0.143.tgz(@elysiajs/eden@1.4.5(elysia@1.4.19(@sinclair/typebox@0.34.41)(exact-mirror@0.2.5(@sinclair/typebox@0.34.41))(file-type@21.1.1)(openapi-types@12.1.3)(typescript@5.9.3)))':
dependencies:
'@elysiajs/eden': 1.4.5(elysia@1.4.19(@sinclair/typebox@0.34.41)(exact-mirror@0.2.5(@sinclair/typebox@0.34.41))(file-type@21.1.1)(openapi-types@12.1.3)(typescript@5.9.3))

View File

@@ -248,7 +248,9 @@ const local: App.I18n.Schema = {
tokenization: 'Tokenization Management',
tokenization_product: 'Tokenization Product',
notification: 'Notification Management',
news: 'News Management'
news: 'News Management',
robot: 'Robot Management',
robot_spot: 'Spot Robot'
},
page: {
login: {

View File

@@ -244,7 +244,9 @@ const local: App.I18n.Schema = {
tokenization: '代币化管理',
tokenization_product: '代币化产品',
notification: '通知管理',
news: '新闻管理'
news: '新闻管理',
robot: '机器人管理',
robot_spot: '现货机器人'
},
page: {
login: {

View File

@@ -26,6 +26,7 @@ export const views: Record<LastLevelRouteKey, RouteComponent | (() => Promise<Ro
home: () => import("@/views/home/index.vue"),
news: () => import("@/views/news/index.vue"),
notification: () => import("@/views/notification/index.vue"),
robot_spot: () => import("@/views/robot/spot/index.vue"),
rwa_product: () => import("@/views/rwa/product/index.vue"),
rwa_producttype: () => import("@/views/rwa/productType/index.vue"),
rwa_subscribe: () => import("@/views/rwa/subscribe/index.vue"),

View File

@@ -133,9 +133,30 @@ export const generatedRoutes: GeneratedRoute[] = [
meta: {
title: 'notification',
i18nKey: 'route.notification',
order: 7
order: 9
}
},
{
name: 'robot',
path: '/robot',
component: 'layout.base',
meta: {
title: 'robot',
i18nKey: 'route.robot',
order: 7
},
children: [
{
name: 'robot_spot',
path: '/robot/spot',
component: 'view.robot_spot',
meta: {
title: 'robot_spot',
i18nKey: 'route.robot_spot'
}
}
]
},
{
name: 'rwa',
path: '/rwa',
@@ -225,6 +246,15 @@ export const generatedRoutes: GeneratedRoute[] = [
order: 4
},
children: [
{
name: 'user_list',
path: '/user/list',
component: 'view.user_list',
meta: {
title: 'user_list',
i18nKey: 'route.user_list'
}
},
{
name: 'user_bankcard',
path: '/user/bankcard',
@@ -234,15 +264,6 @@ export const generatedRoutes: GeneratedRoute[] = [
i18nKey: 'route.user_bankcard'
}
},
{
name: 'user_list',
path: '/user/list',
component: 'view.user_list',
meta: {
title: 'user_list',
i18nKey: 'route.user_list'
}
}
]
},
{

View File

@@ -175,6 +175,8 @@ const routeMap: RouteMap = {
"login": "/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?",
"news": "/news",
"notification": "/notification",
"robot": "/robot",
"robot_spot": "/robot/spot",
"rwa": "/rwa",
"rwa_product": "/rwa/product",
"rwa_producttype": "/rwa/producttype",

View File

@@ -29,6 +29,8 @@ declare module "@elegant-router/types" {
"login": "/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?";
"news": "/news";
"notification": "/notification";
"robot": "/robot";
"robot_spot": "/robot/spot";
"rwa": "/rwa";
"rwa_product": "/rwa/product";
"rwa_producttype": "/rwa/producttype";
@@ -85,6 +87,7 @@ declare module "@elegant-router/types" {
| "login"
| "news"
| "notification"
| "robot"
| "rwa"
| "tokenization"
| "transfer"
@@ -117,6 +120,7 @@ declare module "@elegant-router/types" {
| "home"
| "news"
| "notification"
| "robot_spot"
| "rwa_product"
| "rwa_producttype"
| "rwa_subscribe"

View File

@@ -0,0 +1,230 @@
<script lang="ts" setup>
import { computed, ref, useTemplateRef } from 'vue';
import type { FormInst, FormRules } from 'naive-ui';
import type { Treaty } from '@elysiajs/eden';
import { client, safeClient } from '@/service/api';
defineOptions({ name: 'EditSpotRobotConfig' });
type Data = Treaty.Data<typeof client.api.admin.spot_robot_trader.configs.get>['data'][number];
const props = defineProps<{
data: Data;
}>();
const emit = defineEmits<{
(e: 'close'): void;
}>();
const formRef = useTemplateRef<FormInst | null>('formRef');
const { data: assets } = safeClient(client.api.admin.assets.get({ query: { pageIndex: 1, pageSize: 100 } }));
const { data: users } = safeClient(client.api.admin.users.get({ query: { pageIndex: 1, pageSize: 200 } }));
const { data: tradingPairs } = safeClient(
client.api.admin.trading_pairs.get({ query: { pageIndex: 1, pageSize: 100 } })
);
const assetOptions = computed(
() =>
assets.value?.data.map(asset => ({
label: `${asset.code} - ${asset.name}`,
value: asset.code
})) || []
);
const form = ref({
baseAsset: props.data.baseAsset,
quoteAsset: props.data.quoteAsset,
robotUserId: props.data.robotUserId,
symbol: props.data.symbol,
baseTopUpAmount: props.data.baseTopUpAmount ? Number(props.data.baseTopUpAmount) : 0,
enabled: props.data.enabled,
operatorUserId: props.data.operatorUserId || '',
buyPriceMax: props.data.buyPriceMax ? Number(props.data.buyPriceMax) : 0,
buyPriceMin: props.data.buyPriceMin ? Number(props.data.buyPriceMin) : 0,
buyPriceStep: props.data.buyPriceStep ? Number(props.data.buyPriceStep) : 0
});
const rules: FormRules = {
baseAsset: [
{
required: true,
message: '请输入基础资产',
trigger: ['blur', 'input']
}
],
quoteAsset: [
{
required: true,
message: '请输入计价资产',
trigger: ['blur', 'input']
}
],
robotUserId: [
{
required: true,
message: '请输入机器人用户ID',
trigger: ['blur', 'input']
}
],
symbol: [
{
required: true,
message: '请输入交易对',
trigger: ['blur', 'input']
}
],
baseTopUpAmount: [
{
required: true,
type: 'number',
message: '请输入基础资产单次充值金额',
trigger: ['blur', 'change']
}
],
buyPriceMax: [
{
required: true,
type: 'number',
message: '请输入买入价格上限',
trigger: ['blur', 'change']
}
],
buyPriceMin: [
{
required: true,
type: 'number',
message: '请输入买入价格下限',
trigger: ['blur', 'change']
}
],
buyPriceStep: [
{
required: true,
type: 'number',
message: '请输入买入价格步长',
trigger: ['blur', 'change']
}
]
};
async function handleSubmit() {
formRef.value?.validate(async errors => {
if (!errors) {
const { data } = await safeClient(() =>
client.api.admin.spot_robot_trader.config.put({
id: props.data.id,
baseAsset: form.value.baseAsset,
operatorUserId: form.value.operatorUserId,
quoteAsset: form.value.quoteAsset,
robotUserId: form.value.robotUserId,
symbol: form.value.symbol,
baseTopUpAmount: String(form.value.baseTopUpAmount),
enabled: form.value.enabled,
buyPriceMax: String(form.value.buyPriceMax),
buyPriceMin: String(form.value.buyPriceMin),
buyPriceStep: String(form.value.buyPriceStep)
})
);
if (data) {
window.$message?.success('现货机器人配置更新成功');
emit('close');
}
}
});
}
</script>
<template>
<NForm
ref="formRef"
:model="form"
:rules="rules"
label-width="140px"
label-placement="left"
require-mark-placement="left"
>
<NFormItem label="基础资产" path="baseAsset">
<NSelect v-model:value="form.baseAsset" :options="assetOptions" placeholder="请选择基础资产" filterable />
</NFormItem>
<NFormItem label="计价资产" path="quoteAsset">
<NSelect v-model:value="form.quoteAsset" :options="assetOptions" placeholder="请选择计价资产" filterable />
</NFormItem>
<NFormItem label="机器人用户ID" path="robotUserId">
<NSelect
v-model:value="form.robotUserId"
:options="users?.data.map(user => ({ label: `${user.nickname || user.user.name}`, value: user.userId })) || []"
placeholder="请选择机器人用户"
filterable
/>
</NFormItem>
<NFormItem label="交易对" path="symbol">
<NSelect
v-model:value="form.symbol"
:options="tradingPairs?.data.map(tp => ({ label: tp.symbol, value: tp.symbol })) || []"
placeholder="请选择交易对"
filterable
/>
</NFormItem>
<NFormItem label="基础资产单次充值金额" path="baseTopUpAmount">
<NInputNumber
v-model:value="form.baseTopUpAmount"
:min="0"
:step="0.01"
:precision="8"
placeholder="请输入充值金额"
class="w-full"
/>
</NFormItem>
<NFormItem label="买入价格上限" path="buyPriceMax">
<NInputNumber
v-model:value="form.buyPriceMax"
:min="0"
:step="0.01"
:precision="8"
placeholder="请输入买入价格上限"
class="w-full"
/>
</NFormItem>
<NFormItem label="买入价格下限" path="buyPriceMin">
<NInputNumber
v-model:value="form.buyPriceMin"
:min="0"
:step="0.01"
:precision="8"
placeholder="请输入买入价格下限"
class="w-full"
/>
</NFormItem>
<NFormItem label="买入价格步长" path="buyPriceStep">
<NInputNumber
v-model:value="form.buyPriceStep"
:min="0"
:step="0.01"
:precision="8"
placeholder="请输入买入价格步长"
class="w-full"
/>
</NFormItem>
<NFormItem label="是否启用" path="enabled">
<NSwitch v-model:value="form.enabled">
<template #checked>启用</template>
<template #unchecked>禁用</template>
</NSwitch>
</NFormItem>
<NSpace justify="end" class="mt-4">
<NButton @click="$emit('close')">取消</NButton>
<NButton type="primary" @click="handleSubmit">更新配置</NButton>
</NSpace>
</NForm>
</template>
<style lang="css" scoped></style>

View File

@@ -0,0 +1,143 @@
<script lang="ts" setup>
import { h, useTemplateRef } from 'vue';
import { useDateFormat } from '@vueuse/core';
import { useDialog } from 'naive-ui';
import { client, safeClient } from '@/service/api';
import type { TableBaseColumns, TableFetchData, TableInst } from '@/components/table';
import Edit from './components/edit.vue';
const dialog = useDialog();
const tableInst = useTemplateRef<TableInst>('tableInst');
const fetchData: TableFetchData = ({ pagination, filter }) => {
return safeClient(() =>
client.api.admin.spot_robot_trader.configs.get({
query: {
...pagination,
...filter
}
})
);
};
const columns: TableBaseColumns = [
{
key: 'selection',
title: '序号',
type: 'selection',
width: 60
},
{
key: 'id',
title: 'ID',
width: 100
},
{
key: 'baseAsset',
title: '基础资产',
width: 120
},
{
key: 'quoteAsset',
title: '计价资产',
width: 120
},
{
key: 'robotUserId',
title: '机器人用户ID',
width: 150
},
{
key: 'symbol',
title: '交易对',
width: 100
},
{
key: 'baseTopUpAmount',
title: '基础资产单次充值金额',
width: 160
},
{
key: 'buyPriceMax',
title: '买入价格上限',
width: 140
},
{
key: 'buyPriceMin',
title: '买入价格下限',
width: 140
},
{
key: 'buyPriceStep',
title: '买入价格步长',
width: 140
},
{
key: 'createdAt',
title: '创建时间',
width: 180,
render: (row: any) => {
return useDateFormat(row.createdAt, 'YYYY-MM-DD HH:mm:ss').value;
}
},
{
key: 'enabled',
title: '是否启用',
width: 100,
render: (row: any) => (row.enabled ? '是' : '否')
},
{
key: 'operations',
title: '操作',
fixed: 'right',
width: 150,
operations: (row: any) => [
{
contentText: row.enabled ? '禁用' : '启用',
type: 'primary',
ghost: true,
size: 'small',
onClick: async () => {
await safeClient(
client.api.admin.spot_robot_trader.config.enable.post({
id: row.id
})
);
tableInst.value?.reload();
}
},
{
contentText: '编辑',
type: 'primary',
ghost: true,
size: 'small',
onClick: () => {
handleEdit(row);
}
}
]
}
];
function handleEdit(row: any) {
const dialogInstance = dialog.create({
title: '编辑现货机器人配置',
content: () =>
h(Edit, {
data: row,
onClose: () => {
dialogInstance.destroy();
tableInst.value?.reload();
}
}),
style: { width: '600px' },
showIcon: false
});
}
</script>
<template>
<TableBase ref="tableInst" show-header-operation :columns="columns" :fetch-data="fetchData" :scroll-x="1000" />
</template>
<style lang="css" scoped></style>