2025-11-11 01:59:11    0    0    0
2025-11-10 03:23:33    0    0    0
  1. import { v4 as uuidv4 } from 'uuid'
  2. const { request: updateEnabledRequest, loading: updateSortLoading } = useRequest(switchApi)
  3. /**
  4. * 修改开关状态
  5. */
  6. const handleChangeEnabled = debounce(async (record: Record<string, unknown>) => {
  7. try {
  8. const params = {
  9. id: record?.id,
  10. enabled: !record?.enabled,
  11. }
  12. await updateEnabledRequest({ method: 'put', params })
  13. message.success('修改成功')
  14. } catch {
  15. const newTableData = [...(tableRef?.current?.data?.list ?? [])].map((item) => {
  16. if (item?.id === record?.id) {
  17. return { ...item, rowKey: uuidv4() }
  18. }
  19. return item
  20. })
  21. tableRef.current?.mutate({ list: newTableData, total: tableRef?.current?.data?.total })
  22. }
  23. }, 10)
  24. const columns = [
  25. {
  26. title: '状态',
  27. dataIndex: 'enabled',
  28. width: 80,
  29. render: (text, record) => {
  30. // 按钮权限判断
  31. if (!validatePermission('commodityCenter_lis
2025-11-10 02:47:00    0    0    0

1. 使用 Form.List 动态控制 Table 数据 (最推荐的方式,尤其是编辑型表格)

思路
- 用 Form.List 来存储一组列表数据(比如表格的每一行);
- 每一行的数据作为一个对象;
- Table 的数据源(dataSource)直接绑定到 form.getFieldValue('listName')
- 每列通过 Form.Item 渲染可编辑单元格。

示例

  1. import React from 'react';
  2. import { Form, Input, InputNumber, Button, Table } from 'antd';
  3. const EditableTable = () => {
  4. const [form] = Form.useForm();
  5. return (
  6. <Form form={form} initialValues={{ users: [{ name: '张三', age: 18 }] }}>
  7. <Form.List name="users">
  8. {(fields, { add, remove }) => {
  9. const columns = [
  10. {
  11. title: '姓名',
  12. dataIndex: 'name',
  13. render: (_, __, index) => (
  14. <Form.Item name={[index, 'name']} style={{ marginBottom: 0 }}>
  15. <Input />
  16. </Form.Item>
  17. ),
  18. },
  19. {
  20. title: '年龄',
  21. dataIndex: 'age',
  22. render: (_, __, index) => (
  23. <F
2025-05-09 03:06:13    4    0    0

https://stackoverflow.com/questions/71084718/docker-desktop-stopped-message-after-installation
1. 只需转到配置文件 C:\Users\<username>\AppData\Roaming\Docker\settings.json,然后设置"wslEngineEnabled": true
2. 重启电脑

2025-01-06 01:36:52    13    0    0

该错误主要由于其 Windows Defender 实时保护功能。请按照更改 Windows Defender 计划的步骤进行修复。

  1. Windows键+R。这样会打开“运行”。或者,你可以前往“开始”菜单,然后搜索 “运行”。

  2. 在运行对话框中,输入taskschd.msc并按回车键。

  3. 导航到 任务 计划程序 库> Microsoft > Windows > Windows Defender

  4. 在右侧窗格中,双击“Windows Defender 计划扫描”

  5. 常规选项卡上,取消选中以最高权限运行选项。

  6. 单击“条件”选项卡并取消选中所有选项。

  7. 单击“确定”

2024-05-09 08:28:45    448    0    0

除了直接在渲染逻辑中使用 form.getFieldValueuseWatch 之外,Ant Design Form 还提供了shouldUpdate属性在 Form.Item 组件上,这是另一种实现表单项之间联动的方式。shouldUpdate 允许你根据其他字段的变化来重新渲染 Form.Item,而不需要直接操作表单状态或使用额外的状态管理。这种方法更适合于当你需要根据一个或多个表单项的值变化来改变当前表单项的行为时使用。

使用 shouldUpdate 实现表单项联动
下面是一个使用shouldUpdate 的例子,它展示了如何根据一个单选按钮的选择来显示一个额外的输入框:

  1. import React from 'react';
  2. import { Form, Input, Radio, Button } from 'antd';
  3. const FormItemDependencyWithShouldUpdate = () => {
  4. return (
  5. <Form layout="vertical">
  6. <Form.Item name="choice" label="选择">
  7. <Radio.Group>
  8. <Radio value="option1">选项1</Radio>
  9. <Radio value="option2">选项2</Radio>
  10. </Radio.Group>
  11. </Form.Item>
  12. {/* 使用shouldUpdate监听choice字段的变化 */}
  13. <Form.Item shouldUpdate={(prevValues, currentValues) => prevValues.choice !== currentValues.choice}>
  14. {({ getFieldValue }) => {
  15. return getFieldValue('choice') === 'option2' ? (
  16. <Form.Item
  17. name="inpu
2024-05-08 06:26:25    5    0    0

原因

使用了 listType="picture-card" 后, 删除/上传图片父元素 .ant-upload-list-picture-card 下面会同时存在两个元素, 一个为上传触发元素, 另一个为显示图片的元素

解决

父元素设置 overflow: hidden 来隐藏多余的元素

  1. .ant-upload-list-picture-card {
  2. overflow: hidden;
  3. height: 300px; // 自行设置合适的高度
  4. .ant-upload-select, .ant-upload-list-item-container {
  5. width: 100% !important;
  6. height: 100% !important;
  7. }
  8. }
2024-04-18 03:36:42    18    0    0

组件

  1. // ElevatorScroll.vue
  2. <template>
  3. <div
  4. class="elevator-container"
  5. @touchstart="handleTouchStart"
  6. @touchmove="handleTouchMove"
  7. @touchend="handleTouchEnd"
  8. ref="elevatorContainerRef"
  9. >
  10. <div
  11. class="section"
  12. v-for="(item, index) in items"
  13. :key="item.id"
  14. :ref="`section-${index}`"
  15. >
  16. <slot :item="item.list" :index="index"></slot>
  17. </div>
  18. <div v-if="showHint && consistentDirection" :class="['scroll-hint', hintPosition]"
  19. :style="{ opacity: hintOpacity }">{{ hintMessage }}
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. items: {
  27. type: Array,
  28. required: true,
  29. },
  30. activeSectionDate: {
  31. type: Number,
  32. default: 0,
  33. },
  34. },
  35. data() {
  36. return {
  37. startY: 0,
  38. currentY: 0,
  39. hasMoved: false, // 用于记录是否发生了有效滑动
  40. hintOpacity: 0,
  41. showHint: false,
  42. hintMessage: '',
  43. hintPosition: 'hint-bottom',
  44. initialDirection: n
2024-04-17 06:32:18    6    0    0

组件

  1. // CurrentWeekMenu.vue
  2. <template>
  3. <div class="CurrentWeekMenu_root">
  4. <div class="week_box">
  5. <div v-for="(item, index) in weekList" :key="item.id" class="week-item_box"
  6. :class="activeSectionDate === index ? 'active' : ''" @click="scrollToSection(index)">
  7. <div class="week-item_name">{{ item.name }}</div>
  8. <div class="week-item_date">{{ item.date }}</div>
  9. </div>
  10. </div>
  11. <div class="food-menu_box" ref="foodMenuBoxRef">
  12. <div class="food-menu-group_box" v-for="(weekItem, weekIndex) in thisWeek" :key="weekIndex"
  13. :id="'food-menu-group_' + weekIndex">
  14. <div class="food-menu-item_box" v-for="item in weekItem" :key="item.id" :id="item.id"
  15. @click="checked = !checked">
  16. <div class="food-menu-item_img">
  17. <van-image
  18. width="2.13333rem"
  19. height="1.52rem"
  20. fit="cover"
  21. :src="item.imgUrl"
  22. >
2023-09-25 08:36:43    65    0    0
  1. const ForwardTable = React.forwardRef(InternalTable) as <RecordType extends object = any>(
  2. props: React.PropsWithChildren<TableProps<RecordType>> & { ref?: React.Ref<HTMLDivElement> },
  3. ) => React.ReactElement;
  4. // so u can use
  5. <Table<{id: string, b: number}> />
1/19