当前位置: 首页 > news >正文

使用 AI 生成 页面

当前使用的是 火山引擎 提供的 deepseek-v3-241226

思考

如何让AI可以按自己的想法一步步生成页面?

我们要把要生成的内容分段的给到它,让它按步聚完成。

如生成一个列表页

  • 依据所定义的接口。生成API
  • 依赖定义接口 生成 状态管理模块
  • 依赖上状态管理模块生成 LIST 页面,以及增、删、改、查的UI接口
  • 完善 创建模块,同时修正列表的引用关系
  • 完善 修改模块,同步修正列表的引用关系

将生成的内容转化为文件输出
在这里插入图片描述

生成代码

生成API 以及 Store
{role: 'system',content: '\n' +'你是一个前端开发人员,擅长使用VUE开发,熟悉 [arco.design UI 框架](https://arco.design/vue/docs/start).\n' +'\n' +'#开发组件时严格遵守MVVM框架进行开发。\n' +'- 写业种是按照 API - store - view 的顺序书写。\n' +'- 请使用 TypeScript 语言\n' +'\n' +'## 定义 API\n' +'- 请求数据使用 [axios](https://www.npmjs.com/package/axios). 使用 Promise 处理异步请求,并处理异常。\n' +'- 定义出数据的结构。并导出数据结构供 Store 或者其他需要数据结构的地方使用。\n' +'- 定义出查询、添加、删除、修改等接口。\n' +'\n' +'## 定义 Store\n' +'- 使用 [pinia](https://pinia.vuejs.org/zh/core-concepts/) 的 defineStore 定义当前 Store\n' +'- 依据在API中已经定义好的数据结构,定义出 Store 中的 state.\n' +'- 依据在API中已经定义好的数据结构,定义出 Store 中的 getters.\n' +'- 依赖在API中已经定义出的 查询、添加、删除、修改等接口,定义出 Store 中的 action.\n' +'\n' +'请根据用户提交的 数据结构以及接口生成 API、Store\n' +'\n' +'输出格式,请以 JSON 的形式输出。不需要使用 markdown 语法 json 进行标记\n' +'如:{\n' +'  "/api/user.ts": "user api file content",\n' +'  "/store/user.ts": "user store ts file content"\n' +'}\n'},{role: 'user',content: '\n' +'有数据结构如下\n' +'interface IUserInfo {\n' +'  name: string;\n' +'  age: number;\n' +'  role: string;\n' +'  school: string;\n' +'}\n' +'\n' +'有 API 如下\n' +'- GET /user/list\n' +'- GET /user/{id}\n' +'- PUT /user/{id}\n' +'- POST /user\n' +'- DELETE /user/{id}\n'},
{content: '{\n' +'  "/api/user.ts": "import axios from \'axios\';\\n\\n// 定义数据结构\\nexport interface IUserInfo {\\n  name: string;\\n  age: number;\\n  role: string;\\n  school: string;\\n}\\n\\n// 获取用户列表\\nexport const getUserList = async (): Promise<IUserInfo[]> => {\\n  try {\\n    const response = await axios.get(\'/user/list\');\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error fetching user list:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 获取单个用户信息\\nexport const getUserById = async (id: string): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.get(`/user/${id}`);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error fetching user by id:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 更新用户信息\\nexport const updateUser = async (id: string, userInfo: IUserInfo): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.put(`/user/${id}`, userInfo);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error updating user:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 创建新用户\\nexport const createUser = async (userInfo: IUserInfo): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.post(\'/user\', userInfo);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error creating user:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 删除用户\\nexport const deleteUser = async (id: string): Promise<void> => {\\n  try {\\n    await axios.delete(`/user/${id}`);\\n  } catch (error) {\\n    console.error(\'Error deleting user:\', error);\\n    throw error;\\n  }\\n};",\n' +`  "/store/user.ts": "import { defineStore } from 'pinia';\\nimport { IUserInfo, getUserList, getUserById, updateUser, createUser, deleteUser } from '../api/user';\\n\\n// 定义用户 store\\nexport const useUserStore = defineStore('user', {\\n  state: () => ({\\n    userList: [] as IUserInfo[],\\n    currentUser: null as IUserInfo | null,\\n  }),\\n  getters: {\\n    getUserList: (state) => state.userList,\\n    getCurrentUser: (state) => state.currentUser,\\n  },\\n  actions: {\\n    async fetchUserList() {\\n      this.userList = await getUserList();\\n    },\\n    async fetchUserById(id: string) {\\n      this.currentUser = await getUserById(id);\\n    },\\n    async updateUserInfo(id: string, userInfo: IUserInfo) {\\n      const updatedUser = await updateUser(id, userInfo);\\n      const index = this.userList.findIndex(user => user.name === updatedUser.name);\\n      if (index !== -1) {\\n        this.userList[index] = updatedUser;\\n      }\\n    },\\n    async createNewUser(userInfo: IUserInfo) {\\n      const newUser = await createUser(userInfo);\\n      this.userList.push(newUser);\\n    },\\n    async removeUser(id: string) {\\n      await deleteUser(id);\\n      this.userList = this.userList.filter(user => user.name !== id);\\n    },\\n  },\\n});"\n` +'}',role: 'assistant'},

生成列表页

{role: 'user',content: '\n' +'依据上述生成的 API 以及 Store 写一个 列表页,\n' +'\n' +'功能要求\n' +'- 列表页有搜索功能,列表顶部有添加功能,\n' +'- 列表中有操作项,如修改,删除\n' +'- 删除时请使用 Popconfirm 实现二次确认\n' +'\n' +'书写规范\n' +'- 请严格使用 MVVM 模式开发项目\n' +'- 使用 vue 3.0 setup 模型\n' +'\n' +'注:这里尽可能完善列表页相关的功能,添加、修改等功能只需要有接口即可。\n' +'\n' +'请以JSON的形式输出 如:{\n' +'  "/view/user/list.vue": "list vue file content",\n' +'}\n'},{content: '{\n' +`  "/view/user/list.vue": "<template>\\n  <a-card>\\n    <a-space direction=\\"vertical\\" style=\\"width: 100%\\">\\n      <!-- 搜索和添加按钮 -->\\n      <a-space>\\n        <a-input-search\\n          v-model:value=\\"searchKeyword\\"\\n          placeholder=\\"请输入姓名搜索\\"\\n          @search=\\"handleSearch\\"\\n        />\\n        <a-button type=\\"primary\\" @click=\\"handleAdd\\">添加用户</a-button>\\n      </a-space>\\n\\n      <!-- 用户列表 -->\\n      <a-table :data-source=\\"filteredUserList\\" :columns=\\"columns\\" :rowKey=\\"(record) => record.name\\">\\n        <template #bodyCell=\\"{ column, record }\\">\\n          <!-- 操作列 -->\\n          <template v-if=\\"column.key === 'action'\\">\\n            <a-space>\\n              <a-button type=\\"link\\" @click=\\"handleEdit(record)\\">修改</a-button>\\n              <a-popconfirm\\n                title=\\"确定删除该用户吗?\\"\\n                @confirm=\\"handleDelete(record.name)\\"\\n              >\\n                <a-button type=\\"link\\" danger>删除</a-button>\\n              </a-popconfirm>\\n            </a-space>\\n          </template>\\n        </template>\\n      </a-table>\\n    </a-space>\\n  </a-card>\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, computed, onMounted } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 搜索关键字\\nconst searchKeyword = ref<string>('');\\n\\n// 表格列定义\\nconst columns = [\\n  {\\n    title: '姓名',\\n    dataIndex: 'name',\\n    key: 'name',\\n  },\\n  {\\n    title: '年龄',\\n    dataIndex: 'age',\\n    key: 'age',\\n  },\\n  {\\n    title: '角色',\\n    dataIndex: 'role',\\n    key: 'role',\\n  },\\n  {\\n    title: '学校',\\n    dataIndex: 'school',\\n    key: 'school',\\n  },\\n  {\\n    title: '操作',\\n    key: 'action',\\n  },\\n];\\n\\n// 获取用户列表\\nonMounted(() => {\\n  userStore.fetchUserList();\\n});\\n\\n// 过滤后的用户列表\\nconst filteredUserList = computed(() => {\\n  return userStore.getUserList.filter((user) =>\\n    user.name.includes(searchKeyword.value)\\n  );\\n});\\n\\n// 搜索处理\\nconst handleSearch = () => {\\n  // 搜索逻辑已通过 computed 实现\\n};\\n\\n// 添加用户\\nconst handleAdd = () => {\\n  // 这里可以跳转到添加页面或弹出添加模态框\\n  console.log('添加用户');\\n};\\n\\n// 修改用户\\nconst handleEdit = (record: IUserInfo) => {\\n  // 这里可以跳转到编辑页面或弹出编辑模态框\\n  console.log('修改用户:', record);\\n};\\n\\n// 删除用户\\nconst handleDelete = async (id: string) => {\\n  try {\\n    await userStore.removeUser(id);\\n    console.log('删除成功');\\n  } catch (error) {\\n    console.error('删除失败:', error);\\n  }\\n};\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>"\n` +'}',role: 'assistant'},

生成创建弹窗

{role: 'user',content: '\n' +'依据上述生成的列表页和API以及Store写一个 创建数据的弹窗,创建数据需要与 Store 联动。\n' +'\n' +'功能要求\n' +'- 使用 Modal 的 on-before-ok 方法等创建接口完成后再关闭弹窗,发起请求后 ok-loading 处理 true 状态。\n' +'- 组件添加数据校验功能。同时数据提交时也需要检验。\n' +'\n' +'注:这里尽可能完善《添加数据窗口》相关的功能,同时修改一个 list.vue 中引用的部分。\n' +'\n' +'请以JSON的形式输出 如:{\n' +'  "/view/user/create-modal.vue": "create vue file content",\n' +'  "/view/user/list.vue": "list vue file content"\n' +'}\n'},{content: '{\n' +`  "/view/user/create-modal.vue": "<template>\\n  <a-modal\\n    v-model:visible=\\"visible\\"\\n    title=\\"添加用户\\"\\n    @before-ok=\\"handleSubmit\\"\\n    :ok-loading=\\"loading\\"\\n  >\\n    <a-form :model=\\"formState\\" :rules=\\"rules\\" ref=\\"formRef\\">\\n      <a-form-item label=\\"姓名\\" field=\\"name\\">\\n        <a-input v-model=\\"formState.name\\" placeholder=\\"请输入姓名\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"年龄\\" field=\\"age\\">\\n        <a-input-number v-model=\\"formState.age\\" placeholder=\\"请输入年龄\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"角色\\" field=\\"role\\">\\n        <a-input v-model=\\"formState.role\\" placeholder=\\"请输入角色\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"学校\\" field=\\"school\\">\\n        <a-input v-model=\\"formState.school\\" placeholder=\\"请输入学校\\" />\\n      </a-form-item>\\n    </a-form>\\n  </a-modal>\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, reactive } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport { FormInstance } from '@arco-design/web-vue/es/form';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 控制弹窗显示\\nconst visible = ref<boolean>(false);\\n\\n// 表单引用\\nconst formRef = ref<FormInstance | null>(null);\\n\\n// 表单数据\\nconst formState = reactive<IUserInfo>({\\n  name: '',\\n  age: 0,\\n  role: '',\\n  school: '',\\n});\\n\\n// 表单校验规则\\nconst rules = {\\n  name: [{ required: true, message: '姓名不能为空' }],\\n  age: [{ required: true, message: '年龄不能为空' }],\\n  role: [{ required: true, message: '角色不能为空' }],\\n  school: [{ required: true, message: '学校不能为空' }],\\n};\\n\\n// 提交按钮加载状态\\nconst loading = ref<boolean>(false);\\n\\n// 打开弹窗\\nconst openModal = () => {\\n  visible.value = true;\\n};\\n\\n// 提交表单\\nconst handleSubmit = async () => {\\n  try {\\n    // 校验表单\\n    await formRef.value?.validate();\\n    loading.value = true;\\n    // 调用 Store 创建用户\\n    await userStore.createNewUser(formState);\\n    // 关闭弹窗\\n    visible.value = false;\\n  } catch (error) {\\n    console.error('创建用户失败:', error);\\n  } finally {\\n    loading.value = false;\\n  }\\n};\\n\\n// 暴露 openModal 方法\\ndefineExpose({ openModal });\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>",\n` +`  "/view/user/list.vue": "<template>\\n  <a-card>\\n    <a-space direction=\\"vertical\\" style=\\"width: 100%\\">\\n      <!-- 搜索和添加按钮 -->\\n      <a-space>\\n        <a-input-search\\n          v-model:value=\\"searchKeyword\\"\\n          placeholder=\\"请输入姓名搜索\\"\\n          @search=\\"handleSearch\\"\\n        />\\n        <a-button type=\\"primary\\" @click=\\"handleAdd\\">添加用户</a-button>\\n      </a-space>\\n\\n      <!-- 用户列表 -->\\n      <a-table :data-source=\\"filteredUserList\\" :columns=\\"columns\\" :rowKey=\\"(record) => record.name\\">\\n        <template #bodyCell=\\"{ column, record }\\">\\n          <!-- 操作列 -->\\n          <template v-if=\\"column.key === 'action'\\">\\n            <a-space>\\n              <a-button type=\\"link\\" @click=\\"handleEdit(record)\\">修改</a-button>\\n              <a-popconfirm\\n                title=\\"确定删除该用户吗?\\"\\n                @confirm=\\"handleDelete(record.name)\\"\\n              >\\n                <a-button type=\\"link\\" danger>删除</a-button>\\n              </a-popconfirm>\\n            </a-space>\\n          </template>\\n        </template>\\n      </a-table>\\n    </a-space>\\n  </a-card>\\n\\n  <!-- 添加用户弹窗 -->\\n  <create-modal ref=\\"createModalRef\\" />\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, computed, onMounted } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport CreateModal from './create-modal.vue';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 搜索关键字\\nconst searchKeyword = ref<string>('');\\n\\n// 添加用户弹窗引用\\nconst createModalRef = ref<any>(null);\\n\\n// 表格列定义\\nconst columns = [\\n  {\\n    title: '姓名',\\n    dataIndex: 'name',\\n    key: 'name',\\n  },\\n  {\\n    title: '年龄',\\n    dataIndex: 'age',\\n    key: 'age',\\n  },\\n  {\\n    title: '角色',\\n    dataIndex: 'role',\\n    key: 'role',\\n  },\\n  {\\n    title: '学校',\\n    dataIndex: 'school',\\n    key: 'school',\\n  },\\n  {\\n    title: '操作',\\n    key: 'action',\\n  },\\n];\\n\\n// 获取用户列表\\nonMounted(() => {\\n  userStore.fetchUserList();\\n});\\n\\n// 过滤后的用户列表\\nconst filteredUserList = computed(() => {\\n  return userStore.getUserList.filter((user) =>\\n    user.name.includes(searchKeyword.value)\\n  );\\n});\\n\\n// 搜索处理\\nconst handleSearch = () => {\\n  // 搜索逻辑已通过 computed 实现\\n};\\n\\n// 添加用户\\nconst handleAdd = () => {\\n  createModalRef.value?.openModal();\\n};\\n\\n// 修改用户\\nconst handleEdit = (record: IUserInfo) => {\\n  // 这里可以跳转到编辑页面或弹出编辑模态框\\n  console.log('修改用户:', record);\\n};\\n\\n// 删除用户\\nconst handleDelete = async (id: string) => {\\n  try {\\n    await userStore.removeUser(id);\\n    console.log('删除成功');\\n  } catch (error) {\\n    console.error('删除失败:', error);\\n  }\\n};\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>"\n` +'}',role: 'assistant'},

生成编辑弹窗

{role: 'user',content: '\n' +'依据上述生成的创建弹窗和API以及Store写一个 编辑数据的弹窗,编辑数据需要与 Store 联动。\n' +'\n' +'功能要求\n' +'- 使用 Modal 的 on-before-ok 方法等编辑接口完成后再关闭弹窗,发起请求后 ok-loading 处理 true 状态\n' +'- 组件添加数据校验功能。同时数据提交时也需要检验。\n' +'\n' +'注:这里尽可能完善《编辑数据弹窗》相关的功能,同时修改一个 list.vue 中引用的部分。\n' +'\n' +'请以JSON的形式输出 如:{\n' +'  "/view/user/edit-modal.vue": "edit vue file content",\n' +'  "/view/user/list.vue": "list vue file content"\n' +'}\n'},{content: '{\n' +`  "/view/user/edit-modal.vue": "<template>\\n  <a-modal\\n    v-model:visible=\\"visible\\"\\n    title=\\"编辑用户\\"\\n    @before-ok=\\"handleSubmit\\"\\n    :ok-loading=\\"loading\\"\\n  >\\n    <a-form :model=\\"formState\\" :rules=\\"rules\\" ref=\\"formRef\\">\\n      <a-form-item label=\\"姓名\\" field=\\"name\\">\\n        <a-input v-model=\\"formState.name\\" placeholder=\\"请输入姓名\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"年龄\\" field=\\"age\\">\\n        <a-input-number v-model=\\"formState.age\\" placeholder=\\"请输入年龄\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"角色\\" field=\\"role\\">\\n        <a-input v-model=\\"formState.role\\" placeholder=\\"请输入角色\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"学校\\" field=\\"school\\">\\n        <a-input v-model=\\"formState.school\\" placeholder=\\"请输入学校\\" />\\n      </a-form-item>\\n    </a-form>\\n  </a-modal>\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, reactive } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport { FormInstance } from '@arco-design/web-vue/es/form';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 控制弹窗显示\\nconst visible = ref<boolean>(false);\\n\\n// 表单引用\\nconst formRef = ref<FormInstance | null>(null);\\n\\n// 表单数据\\nconst formState = reactive<IUserInfo>({\\n  name: '',\\n  age: 0,\\n  role: '',\\n  school: '',\\n});\\n\\n// 表单校验规则\\nconst rules = {\\n  name: [{ required: true, message: '姓名不能为空' }],\\n  age: [{ required: true, message: '年龄不能为空' }],\\n  role: [{ required: true, message: '角色不能为空' }],\\n  school: [{ required: true, message: '学校不能为空' }],\\n};\\n\\n// 提交按钮加载状态\\nconst loading = ref<boolean>(false);\\n\\n// 打开弹窗并初始化表单数据\\nconst openModal = (userInfo: IUserInfo) => {\\n  Object.assign(formState, userInfo);\\n  visible.value = true;\\n};\\n\\n// 提交表单\\nconst handleSubmit = async () => {\\n  try {\\n    // 校验表单\\n    await formRef.value?.validate();\\n    loading.value = true;\\n    // 调用 Store 更新用户\\n    await userStore.updateUserInfo(formState.name, formState);\\n    // 关闭弹窗\\n    visible.value = false;\\n  } catch (error) {\\n    console.error('更新用户失败:', error);\\n  } finally {\\n    loading.value = false;\\n  }\\n};\\n\\n// 暴露 openModal 方法\\ndefineExpose({ openModal });\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>",\n` +`  "/view/user/list.vue": "<template>\\n  <a-card>\\n    <a-space direction=\\"vertical\\" style=\\"width: 100%\\">\\n      <!-- 搜索和添加按钮 -->\\n      <a-space>\\n        <a-input-search\\n          v-model:value=\\"searchKeyword\\"\\n          placeholder=\\"请输入姓名搜索\\"\\n          @search=\\"handleSearch\\"\\n        />\\n        <a-button type=\\"primary\\" @click=\\"handleAdd\\">添加用户</a-button>\\n      </a-space>\\n\\n      <!-- 用户列表 -->\\n      <a-table :data-source=\\"filteredUserList\\" :columns=\\"columns\\" :rowKey=\\"(record) => record.name\\">\\n        <template #bodyCell=\\"{ column, record }\\">\\n          <!-- 操作列 -->\\n          <template v-if=\\"column.key === 'action'\\">\\n            <a-space>\\n              <a-button type=\\"link\\" @click=\\"handleEdit(record)\\">修改</a-button>\\n              <a-popconfirm\\n                title=\\"确定删除该用户吗?\\"\\n                @confirm=\\"handleDelete(record.name)\\"\\n              >\\n                <a-button type=\\"link\\" danger>删除</a-button>\\n              </a-popconfirm>\\n            </a-space>\\n          </template>\\n        </template>\\n      </a-table>\\n    </a-space>\\n  </a-card>\\n\\n  <!-- 添加用户弹窗 -->\\n  <create-modal ref=\\"createModalRef\\" />\\n  <!-- 编辑用户弹窗 -->\\n  <edit-modal ref=\\"editModalRef\\" />\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, computed, onMounted } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport CreateModal from './create-modal.vue';\\nimport EditModal from './edit-modal.vue';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 搜索关键字\\nconst searchKeyword = ref<string>('');\\n\\n// 添加用户弹窗引用\\nconst createModalRef = ref<any>(null);\\n// 编辑用户弹窗引用\\nconst editModalRef = ref<any>(null);\\n\\n// 表格列定义\\nconst columns = [\\n  {\\n    title: '姓名',\\n    dataIndex: 'name',\\n    key: 'name',\\n  },\\n  {\\n    title: '年龄',\\n    dataIndex: 'age',\\n    key: 'age',\\n  },\\n  {\\n    title: '角色',\\n    dataIndex: 'role',\\n    key: 'role',\\n  },\\n  {\\n    title: '学校',\\n    dataIndex: 'school',\\n    key: 'school',\\n  },\\n  {\\n    title: '操作',\\n    key: 'action',\\n  },\\n];\\n\\n// 获取用户列表\\nonMounted(() => {\\n  userStore.fetchUserList();\\n});\\n\\n// 过滤后的用户列表\\nconst filteredUserList = computed(() => {\\n  return userStore.getUserList.filter((user) =>\\n    user.name.includes(searchKeyword.value)\\n  );\\n});\\n\\n// 搜索处理\\nconst handleSearch = () => {\\n  // 搜索逻辑已通过 computed 实现\\n};\\n\\n// 添加用户\\nconst handleAdd = () => {\\n  createModalRef.value?.openModal();\\n};\\n\\n// 修改用户\\nconst handleEdit = (record: IUserInfo) => {\\n  editModalRef.value?.openModal(record);\\n};\\n\\n// 删除用户\\nconst handleDelete = async (id: string) => {\\n  try {\\n    await userStore.removeUser(id);\\n    console.log('删除成功');\\n  } catch (error) {\\n    console.error('删除失败:', error);\\n  }\\n};\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>"\n` +'}',role: 'assistant'},

整理上述内容统一格式输出


{role: 'user',content: '\n' +'上述已经生成了,将上述内容整体输出一下。输出格式为\n' +'{\n' +'  "/api/user.ts": "user api file content",\n' +'  "/store/user.ts": "user store ts file content",\n' +'  "/view/user/list.vue": "list vue file content",\n' +'  "/view/user/create-modal.vue": "create vue file content",\n' +'  "/view/user/edit-modal.vue": "edit vue file content"\n' +'}\n'},{content: '{\n' +'  "/api/user.ts": "import axios from \'axios\';\\n\\n// 定义数据结构\\nexport interface IUserInfo {\\n  name: string;\\n  age: number;\\n  role: string;\\n  school: string;\\n}\\n\\n// 获取用户列表\\nexport const getUserList = async (): Promise<IUserInfo[]> => {\\n  try {\\n    const response = await axios.get(\'/user/list\');\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error fetching user list:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 获取单个用户信息\\nexport const getUserById = async (id: string): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.get(`/user/${id}`);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error fetching user by id:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 更新用户信息\\nexport const updateUser = async (id: string, userInfo: IUserInfo): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.put(`/user/${id}`, userInfo);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error updating user:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 创建新用户\\nexport const createUser = async (userInfo: IUserInfo): Promise<IUserInfo> => {\\n  try {\\n    const response = await axios.post(\'/user\', userInfo);\\n    return response.data;\\n  } catch (error) {\\n    console.error(\'Error creating user:\', error);\\n    throw error;\\n  }\\n};\\n\\n// 删除用户\\nexport const deleteUser = async (id: string): Promise<void> => {\\n  try {\\n    await axios.delete(`/user/${id}`);\\n  } catch (error) {\\n    console.error(\'Error deleting user:\', error);\\n    throw error;\\n  }\\n};",\n' +`  "/store/user.ts": "import { defineStore } from 'pinia';\\nimport { IUserInfo, getUserList, getUserById, updateUser, createUser, deleteUser } from '../api/user';\\n\\n// 定义用户 store\\nexport const useUserStore = defineStore('user', {\\n  state: () => ({\\n    userList: [] as IUserInfo[],\\n    currentUser: null as IUserInfo | null,\\n  }),\\n  getters: {\\n    getUserList: (state) => state.userList,\\n    getCurrentUser: (state) => state.currentUser,\\n  },\\n  actions: {\\n    async fetchUserList() {\\n      this.userList = await getUserList();\\n    },\\n    async fetchUserById(id: string) {\\n      this.currentUser = await getUserById(id);\\n    },\\n    async updateUserInfo(id: string, userInfo: IUserInfo) {\\n      const updatedUser = await updateUser(id, userInfo);\\n      const index = this.userList.findIndex(user => user.name === updatedUser.name);\\n      if (index !== -1) {\\n        this.userList[index] = updatedUser;\\n      }\\n    },\\n    async createNewUser(userInfo: IUserInfo) {\\n      const newUser = await createUser(userInfo);\\n      this.userList.push(newUser);\\n    },\\n    async removeUser(id: string) {\\n      await deleteUser(id);\\n      this.userList = this.userList.filter(user => user.name !== id);\\n    },\\n  },\\n});",\n` +`  "/view/user/list.vue": "<template>\\n  <a-card>\\n    <a-space direction=\\"vertical\\" style=\\"width: 100%\\">\\n      <!-- 搜索和添加按钮 -->\\n      <a-space>\\n        <a-input-search\\n          v-model:value=\\"searchKeyword\\"\\n          placeholder=\\"请输入姓名搜索\\"\\n          @search=\\"handleSearch\\"\\n        />\\n        <a-button type=\\"primary\\" @click=\\"handleAdd\\">添加用户</a-button>\\n      </a-space>\\n\\n      <!-- 用户列表 -->\\n      <a-table :data-source=\\"filteredUserList\\" :columns=\\"columns\\" :rowKey=\\"(record) => record.name\\">\\n        <template #bodyCell=\\"{ column, record }\\">\\n          <!-- 操作列 -->\\n          <template v-if=\\"column.key === 'action'\\">\\n            <a-space>\\n              <a-button type=\\"link\\" @click=\\"handleEdit(record)\\">修改</a-button>\\n              <a-popconfirm\\n                title=\\"确定删除该用户吗?\\"\\n                @confirm=\\"handleDelete(record.name)\\"\\n              >\\n                <a-button type=\\"link\\" danger>删除</a-button>\\n              </a-popconfirm>\\n            </a-space>\\n          </template>\\n        </template>\\n      </a-table>\\n    </a-space>\\n  </a-card>\\n\\n  <!-- 添加用户弹窗 -->\\n  <create-modal ref=\\"createModalRef\\" />\\n  <!-- 编辑用户弹窗 -->\\n  <edit-modal ref=\\"editModalRef\\" />\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, computed, onMounted } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport CreateModal from './create-modal.vue';\\nimport EditModal from './edit-modal.vue';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 搜索关键字\\nconst searchKeyword = ref<string>('');\\n\\n// 添加用户弹窗引用\\nconst createModalRef = ref<any>(null);\\n// 编辑用户弹窗引用\\nconst editModalRef = ref<any>(null);\\n\\n// 表格列定义\\nconst columns = [\\n  {\\n    title: '姓名',\\n    dataIndex: 'name',\\n    key: 'name',\\n  },\\n  {\\n    title: '年龄',\\n    dataIndex: 'age',\\n    key: 'age',\\n  },\\n  {\\n    title: '角色',\\n    dataIndex: 'role',\\n    key: 'role',\\n  },\\n  {\\n    title: '学校',\\n    dataIndex: 'school',\\n    key: 'school',\\n  },\\n  {\\n    title: '操作',\\n    key: 'action',\\n  },\\n];\\n\\n// 获取用户列表\\nonMounted(() => {\\n  userStore.fetchUserList();\\n});\\n\\n// 过滤后的用户列表\\nconst filteredUserList = computed(() => {\\n  return userStore.getUserList.filter((user) =>\\n    user.name.includes(searchKeyword.value)\\n  );\\n});\\n\\n// 搜索处理\\nconst handleSearch = () => {\\n  // 搜索逻辑已通过 computed 实现\\n};\\n\\n// 添加用户\\nconst handleAdd = () => {\\n  createModalRef.value?.openModal();\\n};\\n\\n// 修改用户\\nconst handleEdit = (record: IUserInfo) => {\\n  editModalRef.value?.openModal(record);\\n};\\n\\n// 删除用户\\nconst handleDelete = async (id: string) => {\\n  try {\\n    await userStore.removeUser(id);\\n    console.log('删除成功');\\n  } catch (error) {\\n    console.error('删除失败:', error);\\n  }\\n};\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>",\n` +`  "/view/user/create-modal.vue": "<template>\\n  <a-modal\\n    v-model:visible=\\"visible\\"\\n    title=\\"添加用户\\"\\n    @before-ok=\\"handleSubmit\\"\\n    :ok-loading=\\"loading\\"\\n  >\\n    <a-form :model=\\"formState\\" :rules=\\"rules\\" ref=\\"formRef\\">\\n      <a-form-item label=\\"姓名\\" field=\\"name\\">\\n        <a-input v-model=\\"formState.name\\" placeholder=\\"请输入姓名\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"年龄\\" field=\\"age\\">\\n        <a-input-number v-model=\\"formState.age\\" placeholder=\\"请输入年龄\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"角色\\" field=\\"role\\">\\n        <a-input v-model=\\"formState.role\\" placeholder=\\"请输入角色\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"学校\\" field=\\"school\\">\\n        <a-input v-model=\\"formState.school\\" placeholder=\\"请输入学校\\" />\\n      </a-form-item>\\n    </a-form>\\n  </a-modal>\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, reactive } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport { FormInstance } from '@arco-design/web-vue/es/form';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 控制弹窗显示\\nconst visible = ref<boolean>(false);\\n\\n// 表单引用\\nconst formRef = ref<FormInstance | null>(null);\\n\\n// 表单数据\\nconst formState = reactive<IUserInfo>({\\n  name: '',\\n  age: 0,\\n  role: '',\\n  school: '',\\n});\\n\\n// 表单校验规则\\nconst rules = {\\n  name: [{ required: true, message: '姓名不能为空' }],\\n  age: [{ required: true, message: '年龄不能为空' }],\\n  role: [{ required: true, message: '角色不能为空' }],\\n  school: [{ required: true, message: '学校不能为空' }],\\n};\\n\\n// 提交按钮加载状态\\nconst loading = ref<boolean>(false);\\n\\n// 打开弹窗\\nconst openModal = () => {\\n  visible.value = true;\\n};\\n\\n// 提交表单\\nconst handleSubmit = async () => {\\n  try {\\n    // 校验表单\\n    await formRef.value?.validate();\\n    loading.value = true;\\n    // 调用 Store 创建用户\\n    await userStore.createNewUser(formState);\\n    // 关闭弹窗\\n    visible.value = false;\\n  } catch (error) {\\n    console.error('创建用户失败:', error);\\n  } finally {\\n    loading.value = false;\\n  }\\n};\\n\\n// 暴露 openModal 方法\\ndefineExpose({ openModal });\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添加 */\\n</style>",\n` +`  "/view/user/edit-modal.vue": "<template>\\n  <a-modal\\n    v-model:visible=\\"visible\\"\\n    title=\\"编辑用户\\"\\n    @before-ok=\\"handleSubmit\\"\\n    :ok-loading=\\"loading\\"\\n  >\\n    <a-form :model=\\"formState\\" :rules=\\"rules\\" ref=\\"formRef\\">\\n      <a-form-item label=\\"姓名\\" field=\\"name\\">\\n        <a-input v-model=\\"formState.name\\" placeholder=\\"请输入姓名\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"年龄\\" field=\\"age\\">\\n        <a-input-number v-model=\\"formState.age\\" placeholder=\\"请输入年龄\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"角色\\" field=\\"role\\">\\n        <a-input v-model=\\"formState.role\\" placeholder=\\"请输入角色\\" />\\n      </a-form-item>\\n      <a-form-item label=\\"学校\\" field=\\"school\\">\\n        <a-input v-model=\\"formState.school\\" placeholder=\\"请输入学校\\" />\\n      </a-form-item>\\n    </a-form>\\n  </a-modal>\\n</template>\\n\\n<script setup lang=\\"ts\\">\\nimport { ref, reactive } from 'vue';\\nimport { useUserStore } from '@/store/user';\\nimport { IUserInfo } from '@/api/user';\\nimport { FormInstance } from '@arco-design web-vue/es/form';\\n\\n// 使用 Pinia Store\\nconst userStore = useUserStore();\\n\\n// 控制弹窗显示\\nconst visible = ref<boolean>(false);\\n\\n// 表单引用\\nconst formRef = ref<FormInstance | null>(null);\\n\\n// 表单数据\\nconst formState = reactive<IUserInfo>({\\n  name: '',\\n  age: 0,\\n  role: '',\\n  school: '',\\n});\\n\\n// 表单校验规则\\nconst rules = {\\n  name: [{ required: true, message: '姓名不能为空' }],\\n  age: [{ required: true, message: '年龄不能为空' }],\\n  role: [{ required: true, message: '角色不能为空' }],\\n  school: [{ required: true, message: '学校不能为空' }],\\n};\\n\\n// 提交按钮加载状态\\nconst loading = ref<boolean>(false);\\n\\n// 打开弹窗并初始化表单数据\\nconst openModal = (userInfo: IUserInfo) => {\\n  Object.assign(formState, userInfo);\\n  visible.value = true;\\n};\\n\\n// 提交表单\\nconst handleSubmit = async () => {\\n  try {\\n    // 校验表单\\n    await formRef.value?.validate();\\n    loading.value = true;\\n    // 调用 Store 更新用户\\n    await userStore.updateUserInfo(formState.name, formState);\\n    // 关闭弹窗\\n    visible.value = false;\\n  } catch (error) {\\n    console.error('更新用户失败:', error);\\n  } finally {\\n    loading.value = false;\\n  }\\n};\\n\\n// 暴露 openModal 方法\\ndefineExpose({ openModal });\\n</script>\\n\\n<style scoped>\\n/* 样式可以根据需要添`... 17 more characters,role: 'assistant'}

完整代码

用户修改 apikey 即可使用

import OpenAI from "openai";
import fs from "fs";import { fileURLToPath } from "url";
import path, { dirname } from "path";// 获取当前文件的完整路径
const __filename = fileURLToPath(import.meta.url);
// 获取当前文件所在的目录
const __dirname = dirname(__filename);const APIKEY = "";
const MODEL = "deepseek-v3-241226";const wirteFile = (dataJSON) => {for (const [filePath, content] of Object.entries(dataJSON)) {const absolutePath = path.join(__dirname, `./dist/${filePath}`);const dir = path.dirname(absolutePath);// 创建目录if (!fs.existsSync(dir)) {fs.mkdirSync(dir, { recursive: true });}// 写入文件fs.writeFile(absolutePath, content, (err) => {if (err) {console.error(`写入文件 ${absolutePath} 时出错:`, err);} else {console.log(`文件 ${absolutePath} 已成功创建。`);}});}
};const openai = new OpenAI({apiKey: APIKEY,baseURL: "https://ark.cn-beijing.volces.com/api/v3",
});const chatAi = (messages) =>new Promise((resolve, reject) => {openai.chat.completions.create({messages,model: MODEL,response_format: {type: "json_object",},temperature: 0.8,}).then((res) => {resolve(res);});});const systemMessage = `
你是一个前端开发人员,擅长使用VUE开发,熟悉 [arco.design UI 框架](https://arco.design/vue/docs/start).#开发组件时严格遵守MVVM框架进行开发。
- 写业种是按照 API - store - view 的顺序书写。
- 请使用 TypeScript 语言## 定义 API
- 请求数据使用 [axios](https://www.npmjs.com/package/axios). 使用 Promise 处理异步请求,并处理异常。
- 定义出数据的结构。并导出数据结构供 Store 或者其他需要数据结构的地方使用。
- 定义出查询、添加、删除、修改等接口。## 定义 Store
- 使用 [pinia](https://pinia.vuejs.org/zh/core-concepts/) 的 defineStore 定义当前 Store
- 依据在API中已经定义好的数据结构,定义出 Store 中的 state.
- 依据在API中已经定义好的数据结构,定义出 Store 中的 getters.
- 依赖在API中已经定义出的 查询、添加、删除、修改等接口,定义出 Store 中的 action.请根据用户提交的 数据结构以及接口生成 API、Store输出格式,请以 JSON 的形式输出。不需要使用 markdown 语法 json 进行标记
如:{"/api/user.ts": "user api file content","/store/user.ts": "user store ts file content"
}
`;
const userMessage = `
有数据结构如下
interface IUserInfo {name: string;age: number;role: string;school: string;
}有 API 如下
- GET /user/list
- GET /user/{id}
- PUT /user/{id}
- POST /user
- DELETE /user/{id}
`;const messages = [{role: "system",content: systemMessage,},
];const userCreateListMessage = `
依据上述生成的 API 以及 Store 写一个 列表页,功能要求
- 列表页有搜索功能,列表顶部有添加功能,
- 列表中有操作项,如修改,删除
- 删除时请使用 Popconfirm 实现二次确认书写规范
- 请严格使用 MVVM 模式开发项目
- 使用 vue 3.0 setup 模型注:这里尽可能完善列表页相关的功能,添加、修改等功能只需要有接口即可。请以JSON的形式输出 如:{"/view/user/list.vue": "list vue file content",
}
`;const userCreateModalMessage = `
依据上述生成的列表页和API以及Store写一个 创建数据的弹窗,创建数据需要与 Store 联动。功能要求
- 使用 Modal 的 on-before-ok 方法等创建接口完成后再关闭弹窗,发起请求后 ok-loading 处理 true 状态。
- 组件添加数据校验功能。同时数据提交时也需要检验。注:这里尽可能完善《添加数据窗口》相关的功能,同时修改一个 list.vue 中引用的部分。请以JSON的形式输出 如:{"/view/user/create-modal.vue": "create vue file content","/view/user/list.vue": "list vue file content"
}
`;const userEditModalMessage = `
依据上述生成的创建弹窗和API以及Store写一个 编辑数据的弹窗,编辑数据需要与 Store 联动。功能要求
- 使用 Modal 的 on-before-ok 方法等编辑接口完成后再关闭弹窗,发起请求后 ok-loading 处理 true 状态
- 组件添加数据校验功能。同时数据提交时也需要检验。注:这里尽可能完善《编辑数据弹窗》相关的功能,同时修改一个 list.vue 中引用的部分。请以JSON的形式输出 如:{"/view/user/edit-modal.vue": "edit vue file content","/view/user/list.vue": "list vue file content"
}
`;const outputALLMessage = `
上述已经生成了,将上述内容整体输出一下。输出格式为
{"/api/user.ts": "user api file content","/store/user.ts": "user store ts file content","/view/user/list.vue": "list vue file content","/view/user/create-modal.vue": "create vue file content","/view/user/edit-modal.vue": "edit vue file content"
}
`;[userMessage,userCreateListMessage,userCreateModalMessage,userEditModalMessage,outputALLMessage,
].reduce((prePromise, message) => {return prePromise.then((preMessages) => {preMessages.push({ role: "user", content: message });debugger;return chatAi(preMessages).then(({ choices }) =>new Promise((resolve) => {debugger;preMessages.push(choices[0].message);resolve(preMessages);}));});}, Promise.resolve(messages)).then((messages) => {console.log("last", messages);const result = messages.pop();const dataJSON = JSON.parse(result.content);wirteFile(dataJSON);});

生成的内容展示

在这里插入图片描述

import axios from 'axios';// 定义数据结构
export interface IUserInfo {name: string;age: number;role: string;school: string;
}// 获取用户列表
export const getUserList = async (): Promise<IUserInfo[]> => {try {const response = await axios.get('/user/list');return response.data;} catch (error) {console.error('Error fetching user list:', error);throw error;}
};// 获取单个用户信息
export const getUserById = async (id: string): Promise<IUserInfo> => {try {const response = await axios.get(`/user/${id}`);return response.data;} catch (error) {console.error('Error fetching user by id:', error);throw error;}
};// 更新用户信息
export const updateUser = async (id: string, userInfo: IUserInfo): Promise<IUserInfo> => {try {const response = await axios.put(`/user/${id}`, userInfo);return response.data;} catch (error) {console.error('Error updating user:', error);throw error;}
};// 创建新用户
export const createUser = async (userInfo: IUserInfo): Promise<IUserInfo> => {try {const response = await axios.post('/user', userInfo);return response.data;} catch (error) {console.error('Error creating user:', error);throw error;}
};// 删除用户
export const deleteUser = async (id: string): Promise<void> => {try {await axios.delete(`/user/${id}`);} catch (error) {console.error('Error deleting user:', error);throw error;}
};
import { defineStore } from 'pinia';
import { IUserInfo, getUserList, getUserById, updateUser, createUser, deleteUser } from '../api/user';// 定义用户 store
export const useUserStore = defineStore('user', {state: () => ({userList: [] as IUserInfo[],currentUser: null as IUserInfo | null,}),getters: {getUserList: (state) => state.userList,getCurrentUser: (state) => state.currentUser,},actions: {async fetchUserList() {this.userList = await getUserList();},async fetchUserById(id: string) {this.currentUser = await getUserById(id);},async updateUserInfo(id: string, userInfo: IUserInfo) {const updatedUser = await updateUser(id, userInfo);const index = this.userList.findIndex(user => user.name === updatedUser.name);if (index !== -1) {this.userList[index] = updatedUser;}},async createNewUser(userInfo: IUserInfo) {const newUser = await createUser(userInfo);this.userList.push(newUser);},async removeUser(id: string) {await deleteUser(id);this.userList = this.userList.filter(user => user.name !== id);},},
});
<template><a-card><a-space direction="vertical" style="width: 100%"><!-- 搜索和添加按钮 --><a-space><a-input-searchv-model:value="searchKeyword"placeholder="请输入姓名搜索"@search="handleSearch"/><a-button type="primary" @click="handleAdd">添加用户</a-button></a-space><!-- 用户列表 --><a-table :data-source="filteredUserList" :columns="columns" :rowKey="(record) => record.name"><template #bodyCell="{ column, record }"><!-- 操作列 --><template v-if="column.key === 'action'"><a-space><a-button type="link" @click="handleEdit(record)">修改</a-button><a-popconfirmtitle="确定删除该用户吗?"@confirm="handleDelete(record.name)"><a-button type="link" danger>删除</a-button></a-popconfirm></a-space></template></template></a-table></a-space></a-card><!-- 添加用户弹窗 --><create-modal ref="createModalRef" /><!-- 编辑用户弹窗 --><edit-modal ref="editModalRef" />
</template><script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { useUserStore } from '@/store/user';
import { IUserInfo } from '@/api/user';
import CreateModal from './create-modal.vue';
import EditModal from './edit-modal.vue';// 使用 Pinia Store
const userStore = useUserStore();// 搜索关键字
const searchKeyword = ref<string>('');// 添加用户弹窗引用
const createModalRef = ref<any>(null);
// 编辑用户弹窗引用
const editModalRef = ref<any>(null);// 表格列定义
const columns = [{title: '姓名',dataIndex: 'name',key: 'name',},{title: '年龄',dataIndex: 'age',key: 'age',},{title: '角色',dataIndex: 'role',key: 'role',},{title: '学校',dataIndex: 'school',key: 'school',},{title: '操作',key: 'action',},
];// 获取用户列表
onMounted(() => {userStore.fetchUserList();
});// 过滤后的用户列表
const filteredUserList = computed(() => {return userStore.getUserList.filter((user) =>user.name.includes(searchKeyword.value));
});// 搜索处理
const handleSearch = () => {// 搜索逻辑已通过 computed 实现
};// 添加用户
const handleAdd = () => {createModalRef.value?.openModal();
};// 修改用户
const handleEdit = (record: IUserInfo) => {editModalRef.value?.openModal(record);
};// 删除用户
const handleDelete = async (id: string) => {try {await userStore.removeUser(id);console.log('删除成功');} catch (error) {console.error('删除失败:', error);}
};
</script><style scoped>
/* 样式可以根据需要添加 */
</style>
<template><a-modalv-model:visible="visible"title="添加用户"@before-ok="handleSubmit":ok-loading="loading"><a-form :model="formState" :rules="rules" ref="formRef"><a-form-item label="姓名" field="name"><a-input v-model="formState.name" placeholder="请输入姓名" /></a-form-item><a-form-item label="年龄" field="age"><a-input-number v-model="formState.age" placeholder="请输入年龄" /></a-form-item><a-form-item label="角色" field="role"><a-input v-model="formState.role" placeholder="请输入角色" /></a-form-item><a-form-item label="学校" field="school"><a-input v-model="formState.school" placeholder="请输入学校" /></a-form-item></a-form></a-modal>
</template><script setup lang="ts">
import { ref, reactive } from 'vue';
import { useUserStore } from '@/store/user';
import { IUserInfo } from '@/api/user';
import { FormInstance } from '@arco-design/web-vue/es/form';// 使用 Pinia Store
const userStore = useUserStore();// 控制弹窗显示
const visible = ref<boolean>(false);// 表单引用
const formRef = ref<FormInstance | null>(null);// 表单数据
const formState = reactive<IUserInfo>({name: '',age: 0,role: '',school: '',
});// 表单校验规则
const rules = {name: [{ required: true, message: '姓名不能为空' }],age: [{ required: true, message: '年龄不能为空' }],role: [{ required: true, message: '角色不能为空' }],school: [{ required: true, message: '学校不能为空' }],
};// 提交按钮加载状态
const loading = ref<boolean>(false);// 打开弹窗
const openModal = () => {visible.value = true;
};// 提交表单
const handleSubmit = async () => {try {// 校验表单await formRef.value?.validate();loading.value = true;// 调用 Store 创建用户await userStore.createNewUser(formState);// 关闭弹窗visible.value = false;} catch (error) {console.error('创建用户失败:', error);} finally {loading.value = false;}
};// 暴露 openModal 方法
defineExpose({ openModal });
</script><style scoped>
/* 样式可以根据需要添加 */
</style>
<template><a-modalv-model:visible="visible"title="编辑用户"@before-ok="handleSubmit":ok-loading="loading"><a-form :model="formState" :rules="rules" ref="formRef"><a-form-item label="姓名" field="name"><a-input v-model="formState.name" placeholder="请输入姓名" /></a-form-item><a-form-item label="年龄" field="age"><a-input-number v-model="formState.age" placeholder="请输入年龄" /></a-form-item><a-form-item label="角色" field="role"><a-input v-model="formState.role" placeholder="请输入角色" /></a-form-item><a-form-item label="学校" field="school"><a-input v-model="formState.school" placeholder="请输入学校" /></a-form-item></a-form></a-modal>
</template><script setup lang="ts">
import { ref, reactive } from 'vue';
import { useUserStore } from '@/store/user';
import { IUserInfo } from '@/api/user';
import { FormInstance } from '@arco-design web-vue/es/form';// 使用 Pinia Store
const userStore = useUserStore();// 控制弹窗显示
const visible = ref<boolean>(false);// 表单引用
const formRef = ref<FormInstance | null>(null);// 表单数据
const formState = reactive<IUserInfo>({name: '',age: 0,role: '',school: '',
});// 表单校验规则
const rules = {name: [{ required: true, message: '姓名不能为空' }],age: [{ required: true, message: '年龄不能为空' }],role: [{ required: true, message: '角色不能为空' }],school: [{ required: true, message: '学校不能为空' }],
};// 提交按钮加载状态
const loading = ref<boolean>(false);// 打开弹窗并初始化表单数据
const openModal = (userInfo: IUserInfo) => {Object.assign(formState, userInfo);visible.value = true;
};// 提交表单
const handleSubmit = async () => {try {// 校验表单await formRef.value?.validate();loading.value = true;// 调用 Store 更新用户await userStore.updateUserInfo(formState.name, formState);// 关闭弹窗visible.value = false;} catch (error) {console.error('更新用户失败:', error);} finally {loading.value = false;}
};// 暴露 openModal 方法
defineExpose({ openModal });
</script><style scoped>
/* 样式可以根据需要添加 */
</style>

相关文章:

使用 AI 生成 页面

当前使用的是 火山引擎 提供的 deepseek-v3-241226 思考 如何让AI可以按自己的想法一步步生成页面&#xff1f; 我们要把要生成的内容分段的给到它&#xff0c;让它按步聚完成。 如生成一个列表页 依据所定义的接口。生成API依赖定义接口 生成 状态管理模块依赖上状态管理…...

【人工智能】机器学习中的评价指标

机器学习中的评价指标 在机器学习中&#xff0c;评估指标&#xff08;Evaluation Metrics&#xff09;是衡量模型性能的工具。选择合适的评估指标能够帮助我们更好地理解模型的效果以及它在实际应用中的表现。 一般来说&#xff0c;评估指标主要分为三大类&#xff1a;分类、…...

shell脚本运行方式 bash 和./区别

在 Linux 或 macOS 这类基于 Unix 的系统里&#xff0c;使用 ./ 运行脚本和使用 bash 运行脚本存在一些差异&#xff0c;下面为你详细说明&#xff1a; 1. 语法与使用方式 使用 ./ 运行脚本&#xff1a; 若要使用 ./ 来运行脚本&#xff0c;需要确保脚本文件具备可执行权限&a…...

ShardingSphere+达梦数据库分表操作

背景 随着数字经济时代的全面到来&#xff0c;数据量呈现爆炸式增长&#xff0c;传统单机数据库在性能、扩展性和可用性方面面临严峻挑战。分布式数据库技术应运而生&#xff0c;成为解决海量数据存储与处理的关键方案。在这一背景下&#xff0c;Apache ShardingSphere作为一款…...

WordPress上传图片时显示“未提供数据”错误

在WordPress中上传图片时显示“未提供数据”的错误&#xff0c;通常是由多种原因引起的&#xff0c;以下是一些常见的问题及其解决方法&#xff1a; 1. 文件权限问题 WordPress需要正确的文件和目录权限才能正常上传图片。如果权限设置不正确&#xff0c;可能会导致无法上传图…...

AP CSA FRQ Q2 Past Paper 五年真题汇总 2023-2019

Author(wechat): bigshuang2020 ap csa tutor, providing 1-on-1 tutoring. 国际教育计算机老师, 擅长答疑讲解&#xff0c;带学生实践学习。 热爱创作&#xff0c;作品&#xff1a;ap csa原创双语教案&#xff0c;真题梳理汇总&#xff0c; AP CSA FRQ专题冲刺, AP CSA MCQ小题…...

海量数据场景题--查找两个大文件的URL

查找两个大文件共同的URL 给定 a、b 两个文件&#xff0c;各存放 50 亿个 URL&#xff0c;每个 URL 各占 64B&#xff0c;找出 a、b 两个文件共同的 URL。内存限制是 4G。 操作逻辑&#xff1a; 使用哈希函数 hash(URL) % 1000​ 将每个URL映射到0-999的编号 文件A切割为a0, a1…...

Spring AI Alibaba 工具(Function Calling)使用

一、工具(Function Calling)简介 Spring AI Alibaba工具(Function Calling)&#xff1a;https://java2ai.com/docs/1.0.0-M6.1/tutorials/function-calling/ 1、工具(Function Calling) “工具&#xff08;Tool&#xff09;”或“功能调用&#xff08;Function Calling&#xf…...

汽车方向盘开关功能测试的技术解析

随着汽车智能化与电动化的发展&#xff0c;方向盘开关的功能日益复杂化&#xff0c;从传统的灯光、雨刷控制到智能语音、自动驾驶辅助等功能的集成&#xff0c;对开关的可靠性、耐久性及安全性提出了更高要求。本文结合北京沃华慧通测控技术有限公司&#xff08;以下简称“慧通…...

9-100V输入替代CYT5030/LM5030高压双路电流模式PWM控制器

产品描述: PC3530高压 PWM 控制器包含实现推挽和桥式拓扑所需的所有功能&#xff0c;采用电流模式控制&#xff0c;提供两个交替栅极驱动器输出。PC3530内置高压启动稳压器&#xff0c;可在 9V~100V 的宽输入电压范围内工作。芯片内部还集成有误差放大器、精密基准、两级过流保…...

详细讲解c++中线程类thread的实现,stl源码讲解之thread

Thread 本节我们来详细介绍一下c中的线程类thread&#xff0c;在讲解的过程中会用到大量模板的知识&#xff0c;可以去看c详解模板泛型编程&#xff0c;详解类模板的实现为什么不能放在cpp文件_泛型函数 cpo-CSDN博客 源码: template <class _Fn, class... _Args, enable_…...

PostgreSQL详解

第一章&#xff1a;环境部署与基础操作 1.1 多平台安装详解 Windows环境 图形化安装 下载EnterpriseDB安装包&#xff08;含pgAdmin&#xff09; 关键配置项说明&#xff1a; # postgresql.conf优化项 max_connections 200 shared_buffers 4GB work_mem 32MB 服务管理命…...

系统思考—第五项修炼

感谢【汇丰】邀请&#xff0c;为其高阶管理者交付系统思考系列项目。这不仅是一次知识的传递&#xff0c;更是一次认知的升级。 系统思考&#xff0c;作为《第五项修炼》的核心能力&#xff0c;正在帮助越来越多的管理者突破碎片化决策的困局&#xff0c;建立看见全貌的智慧与…...

如何使用QuickAPI生成带参数的数据API(基于原生SQL)

目录 一、示例表结构 二、准备工作 三、创建带参数的数据API 步骤 1&#xff1a;登录 QuickAPI 平台 步骤 2&#xff1a;连接数据库 步骤 3&#xff1a;配置基础信息 步骤 4&#xff1a;编写 SQL 并添加参数 步骤 5&#xff1a;测试并发布API 步骤 6&#xff1a;验证A…...

RHINO 转 STL,解锁 3D 打印与工业应用新通道

一、RHINO 格式介绍 RHINO 是一款功能强大的三维建模软件&#xff0c;其对应的文件格式&#xff08;.3dm&#xff09;能够精确地存储复杂的三维模型数据。它支持多种几何类型&#xff0c;包括 NURBS&#xff08;非均匀有理 B 样条曲线&#xff09;、多边形网格等。这种格式的优…...

PySide6属性选择器设置样式避坑

总所周知&#xff0c;Qt中qss语法支持属性选择器&#xff0c;通过setProperty设置key和value&#xff0c;支持在多种样式之前切换。今天使用了一下PySide6的属性选择器&#xff0c;发现了一个问题。完整代码见最后。 首先&#xff0c;先写一段qss样式&#xff0c;用来设置按键样…...

BKA-CNN-BiLSTM、CNN-BiLSTM、BiLSTM、CNN四模型多变量时序光伏功率预测,附模型报告

BKA-CNN-BiLSTM、CNN-BiLSTM、BiLSTM、CNN四模型多变量时序光伏功率预测&#xff0c;附模型报告 目录 BKA-CNN-BiLSTM、CNN-BiLSTM、BiLSTM、CNN四模型多变量时序光伏功率预测&#xff0c;附模型报告预测效果基本介绍程序设计参考资料 预测效果 基本介绍 BKA-CNN-BiLSTM、CNN-…...

ADS 学习和培训资源 - Keysight ADS

在 Signal Edge Solutions&#xff0c;我们是 Keysight ADS 的忠实用户&#xff0c;因此我们明白&#xff0c;使用和学习这款强大的仿真工具有时可能非常困难。 因此&#xff0c;我们编制了一份清单&#xff0c;列出了一些我们最喜欢的 ADS 学习和培训资源&#xff0c;以帮助您…...

【leetcode刷题记录】(java)数组 链表 哈希表

文章目录 四、题目之&#xff1a;代码随想录(1) 代码随想录&#xff1a;数组[704. 二分查找](https://leetcode.cn/problems/binary-search/)[27. 移除元素](https://leetcode.cn/problems/remove-element/)暴力解:双指针&#xff1a; [977. 有序数组的平方](https://leetcode.…...

ngx_http_core_root

定义在 src\http\ngx_http_core_module.c static char * ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {ngx_http_core_loc_conf_t *clcf conf;ngx_str_t *value;ngx_int_t alias;ngx_uint_t …...

大模型在支气管肺癌预测及临床决策中的应用研究报告

目录 一、引言 1.1 研究背景与意义 1.2 研究目的 二、大模型预测支气管肺癌的原理与技术基础 2.1 大模型简介 2.2 数据收集与预处理 2.3 模型训练与优化 三、术前预测 3.1 病情评估 3.1.1 肿瘤大小、位置及分期预测 3.1.2 转移风险预测 3.2 手术风险预测 3.2.1 患…...

机器人原点丢失后找回原点的解决方案与步骤

机器人原点丢失后找回原点的解决方案与步骤 在机器人运行过程中&#xff0c;原点丢失可能导致定位错误、运动失控等问题&#xff0c;常见于机械臂、AGV&#xff08;自动导引车&#xff09;、3D打印机等设备。以下是针对原点丢失问题的系统性解决方案及详细步骤&#xff0c;涵盖…...

CSS SEO、网页布局、媒体查询

目录 一、SEO 头部三大标签 1. Title 标签&#xff08;标题&#xff09; 核心作用 优化规范 示例 2. Meta Description&#xff08;描述&#xff09; 核心作用 优化规范 示例 3. Viewport 标签&#xff08;视口&#xff09; 核心作用 优化规范 4. 完整 SEO 头部模…...

SolidJS 深度解析:高性能响应式前端框架

SolidJS 是一个新兴的响应式前端框架&#xff0c;以其极致的性能、简洁的语法和接近原生 JavaScript 的开发体验而闻名。它结合了 React 的声明式 UI 和 Svelte 的编译时优化&#xff0c;同时采用细粒度响应式更新&#xff0c;避免了虚拟 DOM&#xff08;Virtual DOM&#xff0…...

基于Spring Boot + Vue的银行管理系统设计与实现

基于Spring Boot Vue的银行管理系统设计与实现 一、引言 随着金融数字化进程加速&#xff0c;传统银行业务向线上化转型成为必然趋势。本文设计并实现了一套基于Spring Boot Vue的银行管理系统&#xff0c;通过模块化架构满足用户、银行职员、管理员三类角色的核心业务需求…...

解决 Ubuntu/Debian 中 `apt-get` 报错 “无法获得锁 /var/lib/dpkg/lock“

问题描述 在 Ubuntu/Debian 系统中运行 sudo apt-get install 或 sudo apt update 时&#xff0c;遇到以下错误&#xff1a; E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录(/var/lib/dpkg/)&#xff0c;是否有其他进程正占用它&#…...

OpenGL 着色器

一、‌着色器基础结构‌ ‌版本声明与入口函数‌ ‌首行版本声明‌&#xff1a;必须指定 GLSL 版本和模式&#xff08;如 #version 450 core&#xff09;‌。 #version 450 core // 声明使用 OpenGL 4.5 Core Profile ‌入口函数‌&#xff1a;所有着色器的入口均为 main() 函…...

代码随想录刷题day53|(二叉树篇)105.从前序与中序遍历序列构造二叉树(▲

目录 一、二叉树基础知识 二、构造二叉树思路 2.1 构造二叉树流程&#xff08;先序中序 2.2 递归思路 三、相关算法题目 四、易错点 一、二叉树基础知识 详见&#xff1a;代码随想录刷题day34|&#xff08;二叉树篇&#xff09;二叉树的递归遍历-CSDN博客 二、构造二叉…...

【leetcode刷题日记】lc.560-和为 K 的子数组

目录 1.题目 2.代码 1.题目 给你一个整数数组 nums 和一个整数 k &#xff0c;请你统计并返回 该数组中和为 k 的子数组的个数 。 子数组是数组中元素的连续非空序列。 示例 1&#xff1a; 输入&#xff1a;nums [1,1,1], k 2 输出&#xff1a;2示例 2&#xff1a; 输入…...

计算机期刊推荐 | 计算机-人工智能、信息系统、理论和算法、软件工程、网络系统、图形学和多媒体, 工程技术-制造, 数学-数学跨学科应用

Computers, Materials & Continua 学科领域&#xff1a; 计算机-人工智能、信息系统、理论和算法、软件工程、网络系统、图形学和多媒体, 工程技术-制造, 数学-数学跨学科应用 期刊类型&#xff1a; SCI/SSCI/AHCI 收录数据库&#xff1a; SCI(SCIE),EI,Scopus,知网(CNK…...

K8S安装及部署calico(亲测有用[特殊字符])

一、 基础部署&#xff08;三台均部署&#xff09; 1. 关闭防火墙并修改网络为aliyun 要保证网络可以使用&#xff0c;可以将DNS的指向修改为114.114.114.114和8.8.8.8这两个。 systemctl stop firewalld && systemctl disable firewalld sed -i s/enforcing/disabl…...

etcd性能测试

etcd性能测试 本文参考官方文档完成etcd性能测试&#xff0c;提供etcd官方推荐的性能测试方案。 1. 理解性能&#xff1a;延迟与吞吐量 etcd 提供稳定、持续的高性能。有两个因素决定性能&#xff1a;延迟和吞吐量。延迟是完成一项操作所花费的时间。吞吐量是在某个时间段内…...

在shell脚本内部获取该脚本所在目录的绝对路径

目录 需求描述 方法一&#xff1a;使用 dirname 和 readlink 命令 方法二&#xff1a;使用 BASH_SOURCE 变量 方法三&#xff1a;仅使用纯 Bash 实现 需求描述 工作中经常有这样情况&#xff0c;需要在脚本内部获取该脚本自己所在目录的绝对路径。 假如有一个脚本/a/b/c/…...

JavaEE企业级开发 延迟双删+版本号机制(乐观锁) 事务保证redis和mysql的数据一致性 示例

提醒 要求了解或者熟练掌握以下知识点 spring 事务mysql 脏读如何保证缓存和数据库数据一致性延迟双删分布式锁并发编程 原子操作类 前言 在起草这篇博客之前 我做了点功课 这边我写的是一个示例代码 数据层都写成了 mock 的形式(来源于 JUnit5) // Dduo import java.u…...

SCI一区 | Matlab实现DBO-TCN-LSTM-Attention多变量时间序列预测

SCI一区 | Matlab实现DBO-TCN-LSTM-Attention多变量时间序列预测 目录 SCI一区 | Matlab实现DBO-TCN-LSTM-Attention多变量时间序列预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.【SCI一区级】Matlab实现DBO-TCN-LSTM-Attention多变量时间序列预测&#xff08;程…...

【Python】天气数据可视化

1. Python进行数据可视化 在数据分析和科学计算领域&#xff0c;Python凭借其强大的库和简洁的语法&#xff0c;成为了众多开发者和科研人员的首选工具。数据可视化作为数据分析的重要环节&#xff0c;能够帮助我们更直观地理解数据背后的规律和趋势。本文将详细介绍如何使用P…...

c#的.Net Framework 的console 项目找不到System.Window.Forms 引用

首先确保是建立的.Net Framework 的console 项目,然后天健reference 应用找不到System.Windows.Forms 引用 打开对应的csproj 文件 在第一个PropertyGroup下添加 <UseWindowsForms>true</UseWindowsForms> 然后在第一个ItemGroup 下添加 <Reference Incl…...

Ubuntu 重置密码方法

目录 修改过 root 密码&#xff0c;重置密码的方法没改过 root 密码‌&#xff0c;重置密码的方法 修改过 root 密码&#xff0c;重置密码的方法 Ubuntu 默认禁用root用户&#xff0c;意思就是安装好Ubuntu系统后&#xff0c;root用户默认是没有密码的&#xff0c;普通用户通过…...

电机控制常见面试问题(二十)

文章目录 一.整流电路绕组接法二.电机为什么需要转速器三.电机转矩产生原理四.电机控制中载波频率大小的确定五.开关周期 Tpwm 一.整流电路绕组接法 为了引出直流的输出&#xff0c;一定要在整流变压器的二次侧引出零线&#xff0c;所以二次侧绕组必须接成星形 一次绕组必须要…...

Linux系统之yum本地仓库创建

目录 一.Linux软件安装 1.Rpm包安装 2.yum本地仓库安装 二.yum本地仓库建立 三.编译 一.Linux软件安装 软件安装共2种安装方式&#xff0c;通过rpm包安装或通过yum仓库库安装。 先下载安装包命令的方式去安装软件包安装结束 得到一个可以执行程序 绝对路径下的程序 1.…...

未来技术的发展趋势与影响分析

区块链技术在版权中的应用越来越受到关注。它的基本原理是通过分布式账本将每一份作品的版权信息储存起来&#xff0c;确保这些信息不可篡改、不可删除。这就意味着&#xff0c;当创作者发布作品时&#xff0c;可以在区块链上登记相关信息。这样&#xff0c;任何人都能验证版权…...

ROS2 架构梳理汇总整理

文章目录 前言正文机器人平台整体架构&#xff08;ROS2&#xff09;图一、个人理解整体架构 ROS2架构图一、个人理解ROS2整体架构图二、开发者整理ROS2整体架构图三、Intel整理ROS2整体架构图四、DDS具体架构说明 ROS2 Control架构图一、官方整整理ROS2 Control整体架构 总结 前…...

蓝桥杯算法精讲:二分查找实战与变种解析

适合人群&#xff1a;蓝桥杯备考生 | 算法竞赛入门者 | 二分查找进阶学习者 目录 一、二分查找核心要点 1. 算法思想 2. 适用条件 3. 算法模板 二、蓝桥杯真题实战 例题&#xff1a;分巧克力&#xff08;蓝桥杯2017省赛&#xff09; 三、二分查找变种与技巧 1. 查找左边…...

多层感知机实现

激活函数 非线性 ReLU函数 修正线性单元 rectified linear unit relu(x)max(0,x) relu的导数&#xff1a; sigmoid函数 s i g m o i d ( x ) 1 1 e − x sigmoid(x)\frac{1}{1e^{-x}} sigmoid(x)1e−x1​ 是一个早期的激活函数 缺点是&#xff1a; 幂运算相对耗时&…...

Linux进程控制--进程创建 | 进程终止 | 进程等待 | 进程替换

1.进程创建 现阶段我们知道进程创建有如下两种方式&#xff0c;起始包括在以后的学习中有两种方式也是最常见的&#xff1a; 1、命令行启动命令(程序、指令)。 2、通过程序自身&#xff0c;使用fork函数创建的子进程。 1.1 fork函数 在linux操作系统中&#xff0c;fork函数是…...

Linux 网络编程(二)——套接字编程简介

文章目录 2 Socket 套接字 2.1 什么是 Socket 2.2 Socket编程的基本操作 2.3 地址信息的表示 2.4 网络字节序和主机字节序的转换 2.4.1 字节序转换 2.4.2 网络地址初始化与分配 2.5 INADDR_ANY 2.6 Socket 编程相关函数 2.7 C标准中的 main 函数声明 2.8 套接字应用…...

串行通信 与 并行通信 对比

总目录 一、并行通信 1. 定义与核心特点 1&#xff09; 定义 并行通信是指通过多条数据线同时传输一组数据的各个位&#xff08;如8位、16位或更多&#xff09;&#xff0c;以字节或字为单位进行数据交换的通信方式。 2&#xff09;核心特点 特点描述传输速度快多位同时传…...

基于springboot+vue的北部湾地区助农平台

开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;…...

Docker技术系列文章,第七篇——Docker 在 CI/CD 中的应用

在当今快速发展的软件开发领域&#xff0c;持续集成与持续部署&#xff08;CI/CD&#xff09;已经成为提高软件交付效率和质量的关键实践。而 Docker 作为一种流行的容器化技术&#xff0c;为 CI/CD 流程提供了强大的支持。通过将应用及其依赖项打包成容器&#xff0c;Docker 确…...

Hive SQL中 ?+.+ 的用法,字段剔除

一、含义 ?. 的用法代表剔除表中的特定字段&#xff0c;建议按照字段顺序列出以确保正确性。 二、参数设置 -- 首先需要设置一个参数&#xff1a; set hive.support.quoted.identifiersNone; --然后指定要剔除哪个字段 select (dateline)?. from test.dm_user_add三、举例…...