This commit is contained in:
神仙都没用 2025-03-21 14:53:12 +08:00
parent 75131abbfd
commit 2a8632ca9f
8 changed files with 409 additions and 1437 deletions

1523
build/cool/eps.d.ts vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import type { App } from "vue";
import { type App } from "vue";
import { useComponent } from "./components";
import { useProvide } from "./provide";
import global from "./utils/global";

View File

@ -1,6 +1,6 @@
const proxy = {
'/dev/': {
target: 'http://127.0.0.1:8001',
target: 'http://127.0.0.1:8888',
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/dev/, '')
},
@ -12,7 +12,7 @@ const proxy = {
}
};
const value = 'dev';
const value = 'prod';
const host = proxy[`/${value}/`]?.target;
export { proxy, host, value };

View File

@ -21,13 +21,6 @@ export default (): ModuleConfig => {
label: '动态路由参数'
},
component: () => import('./views/test/route.vue')
},
{
path: '/demo/test/crud',
meta: {
label: '测试'
},
component: () => import('./views/test/crud.vue')
}
]
};

View File

@ -1,205 +0,0 @@
<template>
<cl-crud ref="Crud">
<cl-row>
<cl-refresh-btn />
<cl-add-btn />
<cl-flex1 />
<cl-search ref="Search" />
</cl-row>
<cl-row>
<cl-table ref="Table" />
</cl-row>
<cl-row>
<cl-flex1 />
<cl-pagination />
</cl-row>
<cl-upsert ref="Upsert" />
</cl-crud>
</template>
<script lang="ts" setup>
defineOptions({
name: 'user-info'
});
import { useCrud, useTable, useUpsert, useSearch } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useDict } from '/$/dict';
import { useI18n } from 'vue-i18n';
import { reactive } from 'vue';
const { service } = useCool();
const { t } = useI18n();
const { dict } = useDict();
const options = reactive({
gender: [
{ label: t('未知'), value: 0, type: 'default' },
{ label: t('男'), value: 1, type: 'success' },
{ label: t('女'), value: 2, type: 'danger' }
],
status: [
{ label: t('禁用'), value: 0, type: 'danger' },
{ label: t('正常'), value: 1, type: 'success' },
{ label: t('已注销'), value: 2, type: 'warning' }
],
loginType: [
{ label: t('小程序'), value: 0, type: 'default' },
{ label: t('公众号'), value: 1, type: 'success' },
{ label: t('H5'), value: 2, type: 'info' }
]
});
const Upsert = useUpsert({
items: [
{
label: t('登录唯一ID'),
prop: 'unionid',
component: { name: 'el-input' },
required: false,
span: 12
},
{
label: t('头像'),
prop: 'avatarUrl',
component: { name: 'cl-upload', props: { size: 120 } },
required: false,
span: 12
},
{
label: t('昵称'),
prop: 'nickName',
component: { name: 'el-input' },
required: true,
span: 12
},
{
label: t('手机号'),
prop: 'phone',
component: { name: 'el-input' },
required: false,
span: 12
},
{
label: t('性别'),
prop: 'gender',
component: { name: 'cl-select', props: { options: options.gender } },
required: true,
value: 0,
span: 12
},
{
label: t('状态'),
prop: 'status',
component: { name: 'cl-select', props: { options: options.status } },
required: true,
value: 1,
span: 12
},
{
label: t('登录方式'),
prop: 'loginType',
component: { name: 'cl-select', props: { options: options.loginType } },
required: true,
value: 0,
span: 12
},
{
label: t('来源'),
prop: 'source',
component: { name: 'cl-select', props: { dict: dict.get('sourceType') } },
required: true,
value: 0,
span: 12
},
{
label: t('密码'),
prop: 'password',
component: { name: 'el-input' },
required: false,
span: 12
},
{
label: t('介绍'),
prop: 'description',
component: { name: 'el-input', props: { type: 'textarea' } },
required: false,
span: 24
},
{
label: t('余额'),
prop: 'balance',
component: { name: 'el-input-number', props: { precision: 2 } },
required: true,
value: 0,
span: 12
},
{
label: t('标题'),
prop: 'goodsName',
component: { name: 'el-input' },
required: true,
span: 12
}
]
});
const Table = useTable({
columns: [
{ label: t('ID'), prop: 'id', minWidth: 120 },
{ label: t('登录唯一ID'), prop: 'unionid', minWidth: 120, showOverflowTooltip: true },
{
label: t('头像'),
prop: 'avatarUrl',
minWidth: 120,
component: { name: 'cl-image', props: { size: ['50px', '50px'] } }
},
{ label: t('昵称'), prop: 'nickName', minWidth: 120, showOverflowTooltip: true },
{ label: t('手机号'), prop: 'phone', minWidth: 120, showOverflowTooltip: true },
{ label: t('性别'), prop: 'gender', minWidth: 120, dict: options.gender },
{ label: t('状态'), prop: 'status', minWidth: 120, dict: options.status },
{ label: t('登录方式'), prop: 'loginType', minWidth: 120, dict: options.loginType },
{ label: t('来源'), prop: 'source', minWidth: 120, dict: dict.get('sourceType') },
{ label: t('标题'), prop: 'goodsName', minWidth: 120, showOverflowTooltip: true },
{ label: t('创建时间'), prop: 'createTime', minWidth: 170, sortable: 'desc' },
{ label: t('更新时间'), prop: 'updateTime', minWidth: 170, sortable: 'custom' }
]
});
const Crud = useCrud(
{
service: service.user.info
},
app => {
app.refresh();
}
);
const Search = useSearch({
items: [
{
label: t('性别'),
prop: 'gender',
component: { name: 'cl-select', props: { options: options.gender } }
},
{
label: t('状态'),
prop: 'status',
component: { name: 'cl-select', props: { options: options.status } }
},
{
prop: 'keyWord',
component: {
name: 'el-input',
props: {
placeholder: t('搜索手机号、昵称'),
clearable: true
}
}
}
]
});
</script>

View File

@ -1,102 +0,0 @@
import { module } from '/@/cool';
import { useBase } from '/$/base';
export function useAi() {
const { api } = module.config('helper');
const { user } = useBase();
// 调用流程
async function invokeFlow(
label: string,
params: any,
streamCb?: ({ isEnd, content }: { isEnd: boolean; content: string }) => void
): Promise<any> {
const stream = !!streamCb;
let cacheText = '';
return new Promise((resolve, reject) => {
fetch(api + '/open/code/gen/data', {
method: 'POST',
headers: {
Authorization: user.token,
'Content-Type': 'application/json'
},
body: JSON.stringify({
params,
label,
stream
})
})
.then(res => {
if (res.body) {
if (stream) {
const reader = res.body.getReader();
const decoder = new TextDecoder('utf-8');
const stream = new ReadableStream({
start(controller) {
function push() {
reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
let text = decoder.decode(value, { stream: true });
if (streamCb) {
if (cacheText) {
text = cacheText + text;
}
if (text.indexOf('data:') == 0) {
text = '\n\n' + text;
}
try {
const arr = text
.split(/\n\ndata:/g)
.filter(Boolean)
.map(e => JSON.parse(e));
arr.forEach(streamCb);
cacheText = '';
} catch (err) {
cacheText = text;
}
}
controller.enqueue(text);
push();
});
}
push();
}
});
return new Response(stream);
} else {
return res.json();
}
}
})
.then(res => {
if (stream) {
return res;
}
if (res.code == 1000) {
resolve(res.data.result);
} else {
reject(res);
}
})
.catch(reject);
});
}
return {
invokeFlow
};
}

View File

@ -1,2 +1 @@
export * from './ai';
export * from './menu';