hongzai
hongzai - 认证专家
life is coding,外包,远程协助,咨询添加微信:H0nGzA1

注册于 2年前

回答
226
文章
7
关注者
27

把crud的form的editDisable删除或者设为false即可

控件用daterangge,给你示例
image.png
image.png

{
        title: "日期范围",
        key: "daterange",
        sortable: true,
        type: "daterange",
        show: false,
        search: { disabled: false, width: 380 },
        form: {
          disabled: true,
          component: {
            props: {
              "time-arrow-control": false,
              "picker-options": { shortcuts: shortcuts },
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
            },
          },
        },
        valueBuilder(row, key) {
          if (!StringUtils.hasEmpty(row.daterangeStart, row.daterangeEnd)) {
            row.daterange = [
              new Date(row.daterangeStart),
              new Date(row.daterangeEnd),
            ];
          }
        },
        valueResolve(row, key) {
          if (row.daterange != null && row.daterange.length > 1) {
            row.start_time = row.daterange[0];
            row.stop_time = row.daterange[1];
          } else {
            row.start_time = null;
            row.stop_time = null;
          }
        },
      },

最简单方式就是前端设置定时器setTimeOut了,还有一种方式就是通过webSocket

你可以在crud里添加共同的字段,在序列化时用serializerMethod字段动态返回数据,或者用to_representation方法返回更多属性,这两种方式都能够实现返回更多的数据,不只是你的表里的字段,也没有表的限制,也可以是其他表,like this
image.png
image.png

class DockingModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    # oid = serializers.SerializerMethodField()  # 订单ID
    # itemId = serializers.SerializerMethodField()  # 商品ID
    # itemImgUrl = serializers.SerializerMethodField()  # 商品图
    # itemTitle = serializers.SerializerMethodField()  # 商品标题
    # itemPrice = serializers.SerializerMethodField()  # 商品价格
    # cpsOrderStatus = serializers.SerializerMethodField()  # 订单状态

    # def get_oid(self, obj):
    #     return OrderModel.objects.get(itemId=obj.itemId).oid

    # def get_itemImgUrl(self, obj):
    #     print(GoodsModel.objects.get(itemId=obj.itemId))
    #     return 'test'
    #
    # def get_itemTitle(self, obj):
    #     return GoodsModel.objects.get(itemId=obj.itemId).itemTitle
    #
    # def get_itemPrice(self, obj):
    #     return GoodsModel.objects.get(itemId=obj.itemId).itemPrice
    #
    # def get_cpsOrderStatus(self, obj):
    #     return GoodsModel.objects.get(itemId=obj.itemId).cpsOrderStatus

    sales = serializers.SerializerMethodField()  # 销量
    regimentalPromotionAmount = serializers.SerializerMethodField()  # 预估

    def get_sales(self, obj):
        return GoodsModel.objects.filter(itemId=obj.itemId).count()

    def get_regimentalPromotionAmount(self, obj):
        return round(random.random(), 2)

    def to_representation(self, instance):
        data = super().to_representation(instance)
        if OrderModel.objects.filter(itemId=instance.itemId).exists():
            data['oid'] = OrderModel.objects.filter(itemId=instance.itemId)[0].oid
        else:
            data['oid'] = ''
        data['itemImgUrl'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].itemImgUrl
        data['itemTitle'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].itemTitle
        data['itemPrice'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].itemPrice / 100
        data['itemStatus'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].get_itemStatus_display()
        data['itemAuditStatus'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].get_itemAuditStatus_display()
        data['itemStock'] = GoodsModel.objects.filter(itemId=instance.itemId)[0].itemStock
        return data

    class Meta:
        model = DockingModel
        fields = "__all__"

vuex里可以找的,具体目录为web/src/store/modules/d2admin/modules/page.js
image.png

拿到d2-crud的ref,操作dom对象设置click事件,新标签页画图ok

发布
问题