Ejemplo n.º 1
0
def gen_serializer(project_name_settings):
    init_django_env(project_name_settings)
    import django
    model_list = []
    model_fk_dict = {}
    app_model_import_dict = {}
    sys_label = ['admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin', 'xadmin_api', 'authtoken', 'social_django']
    for one in django.apps.apps.get_models():
        columns = []
        model_name = one._meta.model.__name__
        model_ver_name = one._meta.verbose_name
        app_label = one._meta.app_label
        if app_label not in sys_label:
            fk_field_list = []
            try:
                app_model_import_dict[app_label].append(model_name)
            except KeyError:
                app_model_import_dict[app_label] = [model_name]
            for filed in one.objects.model._meta.fields:
                name = filed.name
                ver_name = filed.verbose_name
                if isinstance(filed, ForeignKey):
                    help_text = filed.help_text.replace(MAIN_DISPLAY + "__", "")
                    fk_field_list.append(name + "$分割$" + help_text)
            model_fk_dict[model_name] = fk_field_list
            model_list.append(model_name)
    # status_text = serializers.CharField(source="status.text", read_only=True)
    print(model_fk_dict)
    app_name = "xadmin_api"
    serializers_txt = f"""
from rest_framework import serializers
$model_import占位$
    """
    model_import_rows = []
    for app, m_list in app_model_import_dict.items():
        txt = f'from {app}.models import {", ".join(m_list)}\n'
        model_import_rows.append(txt)
    serializers_txt = serializers_txt.replace("$model_import占位$", "".join(model_import_rows))

    print(model_fk_dict)
    for model, fk_field_l in model_fk_dict.items():
        fk_display_p = []
        for one_fk in fk_field_l:
            fk_name, fk_text = one_fk.split("$分割$")
            fk_one_line = f'{fk_name}_text = serializers.CharField(source="{fk_name}.{fk_text}", read_only=True)\n'
            fk_display_p.append(fk_one_line)
        serializers_txt += f"""

class {model}Serializer(serializers.ModelSerializer):
    {"    ".join(fk_display_p)}
    class Meta:
        model = {model}
        fields = "__all__"
        """
    #
    if os.path.exists('../xadmin_api/auto_serializers.py'):
        print("已存在serializers跳过")
    else:
        with open('../xadmin_api/auto_serializers.py', 'w') as fw:
            fw.write(serializers_txt)
Ejemplo n.º 2
0
def migration_from_xadmin(project_name_settings):
    init_django_env(project_name_settings)
    import xadmin
    for one, item in xadmin.site._registry.items():
        print(one._meta.object_name)
        print(item.list_display)
        print(item.list_filter)
        print(item.search_fields)
def gen_table_display(project_name_settings, list_display, focus_model):
    init_django_env(project_name_settings)
    import django

    for one in django.apps.apps.get_models():
        if one._meta.model.__name__ == focus_model:
            print("{")
            for filed in one.objects.model._meta.fields:
                if filed.name in list_display:
                    pass
                else:
                    print("""%s: {
          show: false,
        },""" % (filed.name))
            print("}")
Ejemplo n.º 4
0
def gen_route(project_name_settings):
    init_django_env(project_name_settings)
    import django
    path_list = []
    sys_label = ['admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin', 'xadmin_api', 'authtoken', 'social_django']
    for one in django.apps.apps.get_models():
        if one._meta.app_label not in sys_label:
            url = "/xadmin/" + get_lower_case_name(one._meta.model.__name__)
            one = "{" + f"""
                      name: '{one._meta.verbose_name}',
                      icon: 'smile',
                      path: '{url}',
                      component: './AutoGenPage/{one._meta.model.__name__}List',
                   """ + "}"
            # print(one)
            path_list.append(one)
    with open('../xadmin_api/menu.json', 'w') as fw:
        fw.write("["+",".join(path_list)+"]")
Ejemplo n.º 5
0
def gen_url(project_name_settings):
    init_django_env(project_name_settings)
    import django
    model_list = []
    model_fk_dict = {}
    app_model_import_dict = {}
    sys_label = [
        'admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin',
        'xadmin_api', 'authtoken', 'social_django'
    ]
    for one in django.apps.apps.get_models():
        columns = []
        model_name = one._meta.model.__name__
        model_ver_name = one._meta.verbose_name
        app_label = one._meta.app_label
        if app_label not in sys_label:
            model_list.append(model_name)

    url_txt = f"""from xadmin_api import auto_views
from django.urls import re_path, include, path
from rest_framework.routers import DefaultRouter
    
router = DefaultRouter(trailing_slash=False)
    """

    for model_name in model_list:
        url_txt += f"""
router.register('{get_lower_case_name(model_name)}/?', auto_views.{model_name}ViewSet)
    """

    url_txt += """
urlpatterns = [
        re_path('^', include(router.urls)),
    ]
    """

    if os.path.exists('../xadmin_api/auto_url.py'):
        print("已存在urls跳过")
    else:
        with open('../xadmin_api/auto_url.py', 'w') as fw:
            fw.write(url_txt)
Ejemplo n.º 6
0
def gen_filter(project_name_settings):
    init_django_env(project_name_settings)
    import django

    model_list = []
    model_pic_dict = {}
    model_fk_dict = {}
    model_date_dict = {}
    app_model_import_dict = {}
    sys_label = [
        'admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin',
        'xadmin_api', 'authtoken', 'social_django'
    ]
    for one in django.apps.apps.get_models():
        columns = []
        model_name = one._meta.model.__name__
        model_ver_name = one._meta.verbose_name
        app_label = one._meta.app_label
        if app_label not in sys_label:
            try:
                app_model_import_dict[app_label].append(model_name)
            except KeyError:
                app_model_import_dict[app_label] = [model_name]
            img_field_list = []
            fk_field_list = []
            date_field_list = []
            for filed in one.objects.model._meta.fields:
                name = filed.name
                ver_name = filed.verbose_name
                if isinstance(filed, ImageField):
                    img_field_list.append('"' + name + '"')
                if isinstance(filed, FileField):
                    img_field_list.append('"' + name + '"')
                if isinstance(filed, ForeignKey):
                    help_text = filed.help_text.replace(
                        MAIN_DISPLAY + "__", "")
                    fk_field_list.append(name + "$分割$" + help_text)
                if isinstance(filed, DateTimeField):
                    date_field_list.append(name)
            model_pic_dict[model_name] = img_field_list
            model_fk_dict[model_name] = fk_field_list
            model_date_dict[model_name] = date_field_list
            model_list.append(model_name)
    app_name = "xadmin_api"
    filters_txt = f"""
from django_filters import rest_framework as filters
from xadmin_api.custom import DateFromToRangeFilter
$model_import占位$
        """
    model_import_rows = []
    for app, m_list in app_model_import_dict.items():
        txt = f'from {app}.models import {", ".join(m_list)}\n'
        model_import_rows.append(txt)
    filters_txt = filters_txt.replace("$model_import占位$",
                                      "".join(model_import_rows))
    for (model,
         img_field_l), (model_2, fk_field_l), (model_3, date_field_l) in zip(
             model_pic_dict.items(), model_fk_dict.items(),
             model_date_dict.items()):
        fk_display_p = []
        for one_fk in fk_field_l:
            fk_name, fk_text = one_fk.split("$分割$")
            fk_one_line = f'    {fk_name}_text = filters.CharFilter(field_name="{fk_name}")\n'
            fk_display_p.append(fk_one_line)
        date_range_p = []
        for one_date in date_field_l:
            date_one_line = f'    {one_date} = DateFromToRangeFilter(field_name="{one_date}")\n'
            date_range_p.append(date_one_line)
        filters_txt += f"""

class {model}Filter(filters.FilterSet):
{"".join(fk_display_p)}{"".join(date_range_p)}
    class Meta:
        model = {model}
        exclude = [{",".join(img_field_l)}]
    """

    if os.path.exists('../xadmin_api/auto_filters.py'):
        print("已存在filters.py跳过")
    else:
        with open('../xadmin_api/auto_filters.py', 'w') as fw:
            fw.write(filters_txt)
Ejemplo n.º 7
0
def gen_view(project_name_settings):
    init_django_env(project_name_settings)
    import django
    model_list = []
    app_name = "xadmin_api"
    model_search_dict = {}
    app_model_import_dict = {}
    sys_label = [
        'admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin',
        'xadmin_api', 'authtoken', 'social_django'
    ]
    for one in django.apps.apps.get_models():

        model_name = one._meta.model.__name__
        model_ver_name = one._meta.verbose_name
        app_label = one._meta.app_label
        if app_label not in sys_label:
            try:
                app_model_import_dict[app_label].append(model_name)
            except KeyError:
                app_model_import_dict[app_label] = [model_name]
            search_list = []
            model_list.append(model_name)
            for filed in one.objects.model._meta.fields:
                name = filed.name
                ver_name = filed.verbose_name
                if isinstance(filed, CharField):
                    search_list.append('"' + name + '"')
                elif isinstance(filed, CharField):
                    search_list.append('"' + name + '"')
            model_search_dict[model_name] = search_list
    serializers_list = [one + "Serializer" for one in model_list]
    filters_list = [one + "Filter" for one in model_list]
    viewset_txt = f"""
    from rest_framework import viewsets
    from xadmin_api.custom import XadminViewSet
    $model_import占位$
    from {app_name}.auto_serializers import {", ".join(serializers_list)}
    from {app_name}.auto_filters import {", ".join(filters_list)}
    """
    model_import_rows = []
    print(app_model_import_dict)
    for app, m_list in app_model_import_dict.items():
        txt = f'from {app}.models import {", ".join(m_list)}\n'
        model_import_rows.append(txt)
    viewset_txt = viewset_txt.replace("$model_import占位$",
                                      "".join(model_import_rows))
    for model_name in model_list:
        viewset_txt += f"""
    
    class {model_name}ViewSet(XadminViewSet):
            serializer_class = {model_name}Serializer
            queryset = {model_name}.objects.all()
            filter_class = {model_name}Filter
            search_fields = [{",".join(model_search_dict[model_name])}]
        """
    if os.path.exists('../xadmin_api/auto_views.py'):
        print("已存在views跳过")
    else:
        with open('../xadmin_api/auto_views.py', 'w') as fw:
            fw.write(viewset_txt)
def gen_antd_pages(project_name_settings,
                   focus_model=None,
                   template_type="base"):
    init_django_env(project_name_settings)
    import django
    sys_label = [
        'admin', 'auth', 'contenttypes', 'sessions', 'captcha', 'xadmin',
        'xadmin_api', 'authtoken', 'social_django'
    ]
    # focus_model = "CourseResource"
    model_pic_dict = {}
    model_date_dict = {}
    user = get_user_model()
    for one in django.apps.apps.get_models():
        columns = []
        model_name = one._meta.model.__name__
        model_ver_name = one._meta.verbose_name
        if focus_model and model_name != focus_model:
            continue
        if one._meta.app_label not in sys_label:
            img_field_list = []
            date_row_list = []
            model_add_item_list = []
            model_many_to_many_list = []
            model_import_item_list = []
            date_field_list = []
            fileds_num = len(one.objects.model._meta.fields)

            for filed in one.objects.model._meta.fields:
                name = filed.name
                ver_name = filed.verbose_name
                if isinstance(filed, ForeignKey):
                    rela_model = filed.related_model._meta.object_name
                    help_text = filed.help_text.replace(
                        MAIN_DISPLAY + "__", "")
                    one_c = """{
                              title: '%s',
                              dataIndex: '%s',
                              backendType: 'foreignKey',
                              rules: [
                                {
                                  required: true,
                                  message: '%s为必填项',
                                },
                              ],
                                    renderFormItem: (item, {value, onChange}) => {
            const children = $模型名字$ForeignKeyList.map((item) => {
              return <Option key={item.id} value={item.id}>{item.$外键显示字段$}</Option>;
            });
            return <Select
              placeholder="请选择$模型显示名字$"
              onChange={onChange}
            >
              {children}
            </Select>;
          },
                            },""" % (ver_name, name, ver_name)
                    one_c = one_c.replace("$模型名字$", name)
                    one_c = one_c.replace("$外键显示字段$", help_text)
                    one_c = one_c.replace("$模型显示名字$", filed.verbose_name)
                    model_add_item = """const [$模型名字$ForeignKeyList, set$模型名字首字母大写$ForeignKeyList] = useState([]);
      useEffect(() => {
        query$关联Model$().then(value => {
          set$模型名字首字母大写$ForeignKeyList(value.data);
        });
      }, []);""".replace("$模型名字$",
                         name).replace("$模型名字首字母大写$",
                                       name[0].upper() + name[1:]).replace(
                                           "$关联Model$", rela_model)
                    model_add_item_list.append(model_add_item)
                    model_import_item = """import {query$关联Model$} from '@/pages/AutoGenPage//$关联Model$List/service';""".replace(
                        "$关联Model$", rela_model)
                    model_import_item_list.append(model_import_item)
                elif isinstance(filed, CharField):
                    if filed.choices:
                        filed_choices_list = []
                        for filed_one in filed.choices:
                            one_line = f'{filed_one[0]}:"{filed_one[1]}"'
                            filed_choices_list.append(one_line)
                        one_c = """{
                                           title: '%s',
                                           dataIndex: '%s',
                                           rules: [
                                             {
                                               required: true,
                                               message: '%s为必填项',
                                             },
                                           ],
                                           valueEnum: {
                                             $valueEnum$
                                            },
                                         },""" % (ver_name, name, ver_name)
                        one_c = one_c.replace("$valueEnum$",
                                              ",".join(filed_choices_list))
                    elif name == "password":
                        one_c = """{
                                          title: '%s',
                                          dataIndex: '%s',
                                          hideInTable: true,
                                                                        hideInForm: true,
                                  hideInSearch: true,
                                          rules: [
                                            {
                                              required: true,
                                              message: '%s为必填项',
                                            },
                                          ],
                                        },""" % (ver_name, name, ver_name)
                    else:
                        one_c = """{
                      title: '%s',
                      dataIndex: '%s',
                      rules: [
                        {
                          required: true,
                          message: '%s为必填项',
                        },
                      ],
                    },""" % (ver_name, name, ver_name)
                elif name == "id":
                    one_c = """{
                                  title: '%s',
                                  dataIndex: '%s',
                                  hideInForm: true,
                                  hideInSearch: true,
                                  rules: [
                                    {
                                      required: true,
                                      message: '%s为必填项',
                                    },
                                  ],
                                },""" % (ver_name, name, ver_name)
                elif isinstance(filed, DateTimeField):
                    print(filed.default)
                    hideInform = None
                    if filed.default != django.db.models.NOT_PROVIDED or filed.auto_now == True:
                        hideInform = True
                    one_c = """{
              title: '%s',
              dataIndex: '%s',
              valueType: 'dateTime',
              $隐藏form$
              rules: [
                {
                  required: true,
                  message: '%s为必填项',
                },
              ],
                                       render: (text, record) => {
          return dealDateTimeDisplay(text);
        },
            },""" % (ver_name, name, ver_name)
                    if hideInform:
                        one_c = one_c.replace("$隐藏form$", "hideInForm: true,")
                    else:
                        one_c = one_c.replace("$隐藏form$", "")
                    date_field_list.append('"' + name + '"')
                    date_row_list.append(
                        f'record.{name} = moment(record.{name});')
                elif isinstance(filed, DateField):
                    if filed.auto_now == True:
                        pass
                    one_c = """{
                         title: '%s',
                         dataIndex: '%s',
                         valueType: 'date',
                         rules: [
                           {
                             required: true,
                             message: '%s为必填项',
                           },
                         ],
                       },""" % (ver_name, name, ver_name)
                    date_field_list.append('"' + name + '"')
                    date_row_list.append(
                        f'record.{name} = moment(record.{name});')
                elif isinstance(filed, BooleanField):
                    one_c = """{
                                  title: '%s',
                                  dataIndex: '%s',
                                  rules: [
                                    {
                                      required: true,
                                      message: '%s为必填项',
                                    },
                                  ],
                                      render: (text, record) => {
          return BooleanDisplay(text);
        },
                                      renderFormItem: (_, {type, defaultRender, ...rest}, form) => {
          const is_value = form.getFieldValue('%s');
          if (type === "form" && !is_value) {
            form.setFieldsValue({'%s': false});
          }
          return <Switch checked={is_value} onClick={(checked) => {
            form.setFieldsValue({'%s': checked});
          }} />;
        },
                                },""" % (ver_name, name, ver_name, name, name,
                                         name)
                elif isinstance(filed, IntegerField) or isinstance(
                        filed, FloatField):
                    if filed.choices:
                        filed_choices_list = []
                        for filed_one in filed.choices:
                            one_line = f'{filed_one[0]}:"{filed_one[1]}"'
                            filed_choices_list.append(one_line)
                            one_c = """{
                                          title: '%s',
                                          dataIndex: '%s',
                                          rules: [
                                            {
                                              required: true,
                                              message: '%s为必填项',
                                            },
                                          ],
                                           valueEnum: {
                                                     $valueEnum$
                                                    },
                                        },""" % (ver_name, name, ver_name)
                            one_c = one_c.replace("$valueEnum$",
                                                  ",".join(filed_choices_list))
                    else:
                        one_c = """{
                                      title: '%s',
                                      dataIndex: '%s',
                                                valueType: 'digit',
                                      rules: [
                                        {
                                          required: true,
                                          message: '%s为必填项',
                                        },
                                      ],
                                    },""" % (ver_name, name, ver_name)
                elif isinstance(filed, ImageField) or isinstance(
                        filed, SImageField):
                    img_field_list.append('"' + name + '"')
                    help_text = filed.help_text

                    if help_text == MAIN_AVATAR:
                        one_c = """{
                            title: '%s',
                            dataIndex: '%s',
                     valueType: 'avatar',
                                   hideInSearch: true,
                            rules: [
                              {
                                required: true,
                                message: '%s为必填项',
                              },
                            ],
                            renderFormItem: (_, {type, defaultRender, ...rest}, form) => {
          const imageUrl = form.getFieldValue('%s');
          return <UploadAvatar img={imageUrl}/>
        },
                          },""" % (ver_name, name, ver_name, name)
                    elif help_text == MAIN_PIC:
                        one_c = """{
                            title: '%s',
                            dataIndex: '%s',
                                          render: (text, record) => {
                      return <img src={text} width="80px" alt=""/>
                    },
                                  hideInSearch: true,
                            rules: [
                              {
                                required: true,
                                message: '%s为必填项',
                              },
                            ],
                             renderFormItem: (_, {type, defaultRender, ...rest}, form) => {
          const imageUrl = form.getFieldValue('%s');
          return <UploadAvatar img={imageUrl}/>
        },
                          },""" % (ver_name, name, ver_name, name)
                elif isinstance(filed, FileField):
                    img_field_list.append('"' + name + '"')
                    one_c = """{
                                                            title: '%s',
                                                            dataIndex: '%s',
                                                                   hideInSearch: true,
                                                            rules: [
                                                              {
                                                                required: true,
                                                                message: '%s为必填项',
                                                              },
                                                            ],
                                                                render: (text, record) => {
                          return <a download={text.split('/').slice(-1)} href={text}>{text.split('/').slice(-1)}</a>;
                        },    renderFormItem: (_, {type, defaultRender, ...rest}, form) => {
                          const downloadUrl = form.getFieldValue('download');
                          return fileUpload(downloadUrl);
                        },
    
                                                          },""" % (
                        ver_name, name, ver_name)
                elif filed.__class__.__name__ == "TextField":
                    one_c = """{
                                  title: '%s',
                                  dataIndex: '%s',
                                valueType: 'textarea',
                                 ellipsis: true,
                                  rules: [
                                    {
                                      required: true,
                                      message: '%s为必填项',
                                    },
                                  ],
                                },""" % (ver_name, name, ver_name)
                elif filed.__class__.__name__ == "UEditorField" or isinstance(
                        filed, richTextField):
                    one_c = """{
                                  title: '%s',
                                  dataIndex: '%s',
                                      customCol:richCol,
                                      ellipsis: true,
                                                                    hideInSearch: true,
                                  rules: [
                                    {
                                      required: true,
                                      message: '%s为必填项',
                                    },
                                  ],
                                      renderFormItem: (_, {type, defaultRender, ...rest}, form) => {
          return richForm(form, rest.id);
        },
                                },""" % (ver_name, name, ver_name)
                else:
                    print(filed.__class__.__name__)
                    one_c = """{
                  title: '%s',
                  dataIndex: '%s',
                  rules: [
                    {
                      required: true,
                      message: '%s为必填项',
                    },
                  ],
                },""" % (ver_name, name, ver_name)
                model_pic_dict[model_name] = img_field_list
                model_date_dict[model_name] = date_field_list
                columns.append(one_c)

            for filed in one.objects.model._meta.many_to_many:
                black_many_to_many = [
                    "groups", "permissions", "user_permissions"
                ]
                if one._meta.model == user and filed.name in black_many_to_many:
                    continue
                else:
                    name = filed.name
                    ver_name = filed.verbose_name
                    rela_model = filed.related_model._meta.object_name
                    help_text = filed.help_text.replace(
                        MAIN_DISPLAY + "__", "")
                    one_c = """{
                      title: '%s',
                      dataIndex: '%s',
                      rules: [
                        {
                          required: true,
                          message: '%s为必填项',
                        },
                      ],
                      renderFormItem: (item, {value, onChange}) => {
              const children = %sManyToManyList.map(item => {
                return (
                  <Option key={item.id} value={item.id}>
                    {item.%s}
                  </Option>
                );
              });
              return (
                <Select mode="multiple" placeholder="请选择%s" onChange={onChange}>
                  {children}
                </Select>
              );
            },
                render: (text, record) => {
              const color_arr = [
                'green',
                'cyan',
                'blue',
                'geekblue',
                'purple',
                'magenta',
                'red',
                'volcano',
                'orange',
                'gold',
                'lime',
              ];
              const child = [];
              text.forEach((value, index, arr) => {
                child.push(<Tag color={color_arr[value $百分$ 10]}>{%sManyToManyMap[value]}</Tag>);
              });
              return <Space>{child}</Space>;
            },
                    },""" % (ver_name, name, ver_name, name, help_text,
                             ver_name, name)
                    one_c = one_c.replace("$百分$", "%")
                    model_many_to_many_item = """const [$模型名字$ManyToManyList, set$模型名字首字母大写$ManyToManyList] = useState([]);
                      const [$模型名字$ManyToManyMap, set$模型名字首字母大写$ManyToManyMap] = useState([]);
                    useEffect(() => {
                      query$关联Model$().then(value => {
                        set$模型名字首字母大写$ManyToManyList(value.data);
                        let get$模型名字首字母大写$ManyToManyMap = {};
              for (let index in value.data) {
                let item = value.data[index];
                get$模型名字首字母大写$ManyToManyMap[item.id.toString()] = item.$关联字段$;
              }
              set$模型名字首字母大写$ManyToManyMap(get$模型名字首字母大写$ManyToManyMap);
                      });
                    }, []);""".replace("$模型名字$", name).replace("$模型名字首字母大写$", name[0].upper() + name[1:]) \
                        .replace("$关联Model$", rela_model).replace("$关联字段$", help_text)
                    model_many_to_many_list.append(model_many_to_many_item)
                    model_import_item = """import {query$关联Model$} from '@/pages/AutoGenPage//$关联Model$List/service';""".replace(
                        "$关联Model$", rela_model)
                    model_import_item_list.append(model_import_item)
                    columns.append(one_c)
            opera = """    {
                              title: '操作',
                              dataIndex: 'option',
                              valueType: 'option',
                                    fixed: 'right',
          width: 100,
                              render: (text, record) => (
                                <>
    
                                  <EditOutlined title="编辑" className="icon" onClick={async () => {
                                    $时间处理占位$
                                    handleUpdateModalVisible(true);
                                    setUpdateFormValues(record);
                                  }} />
                                  <Divider type="vertical" />
                                  <Popconfirm
                                    title="您确定要删除$模型名字$吗?"
                                    placement="topRight"
                                    onConfirm={() => {
                                      handleRemove([record])
                                      actionRef.current.reloadAndRest();
                                    }}
                                    okText="确定"
                                    cancelText="取消"
                                  >
                                    <DeleteOutlined title="删除" className="icon" />
                                  </Popconfirm>
                                </>
                              ),
                            },""".replace("$模型名字$", model_ver_name)
            opera = opera.replace("$时间处理占位$", "".join(date_row_list))
            columns.append(opera)
            dest_path = f'./antd_page_templates/{template_type}'
            with open(f'{dest_path}/index.jsx') as fr:

                content = fr.read()
                if fileds_num > 8:
                    new_content = content.replace(
                        "$两列布局占位$", """          search={{
                                span: {
                                  lg: 12,
                                  md: 12,
                                  xxl: 12,
                                  xl: 12,
                                  sm: 12,
                                  xs: 24,
                                },
                              }}""")
                else:
                    new_content = content.replace("$两列布局占位$", "")
                new_content = new_content.replace("$占位列数据$", "".join(columns))
                new_content = new_content.replace("$占位模型名$", model_name)
                new_content = new_content.replace("$占位模型显示名$",
                                                  str(model_ver_name))
                new_content = new_content.replace("$外键占位$",
                                                  "".join(model_add_item_list))
                new_content = new_content.replace(
                    "$多对多占位$", "".join(model_many_to_many_list))
                new_content = new_content.replace(
                    "$import占位$", "".join(model_import_item_list))
                new_content = new_content.replace(
                    "$时间占位$", ",".join(model_date_dict[model_name]))

            if len(model_pic_dict[model_name]) > 0:
                with open(f'{dest_path}/service_img.js') as fr:
                    content = fr.read()
                    new_services = content.replace(
                        "$占位path$", get_lower_case_name(model_name))
                    new_services = new_services.replace("$占位模型名$", model_name)
                    new_services = new_services.replace(
                        "$图片字段列表$", ",".join(model_pic_dict[model_name]))
            else:
                with open(f'{dest_path}/service.js') as fr:
                    content = fr.read()
                    new_services = content.replace(
                        "$占位path$", get_lower_case_name(model_name))
                    new_services = new_services.replace("$占位模型名$", model_name)
            with open(f'{dest_path}/components/CreateForm.jsx') as fr:
                create_form = fr.read()
                create_form = create_form.replace("$占位模型显示名$",
                                                  str(model_ver_name))
                if fileds_num > 8:
                    create_form = create_form.replace("$宽度占位$", 'width={1200}')
                else:
                    create_form = create_form.replace("$宽度占位$", "width={600}")
            with open(f'{dest_path}/components/UpdateForm.jsx') as fr:
                update_form = fr.read()
                update_form = update_form.replace("$占位模型显示名$",
                                                  str(model_ver_name))
                if fileds_num > 8:
                    update_form = update_form.replace("$宽度占位$", 'width={1200}')
                else:
                    update_form = update_form.replace("$宽度占位$", "width={600}")
            target_path = '../xadmin/src/pages/AutoGenPage'
            cur_path = f'{target_path}/{model_name}List'
            if not os.path.exists(cur_path):
                os.mkdir(cur_path)
            cur_path_co = f'{target_path}/{model_name}List/components'
            if not os.path.exists(cur_path_co):
                os.mkdir(cur_path_co)
            with open(f'{target_path}/{model_name}List/index.jsx', 'w') as fw:
                fw.write(new_content)
            with open(f'{target_path}/{model_name}List/service.js', 'w') as fw:
                fw.write(new_services)
            with open(
                    f'{target_path}/{model_name}List/components/CreateForm.jsx',
                    'w') as fw:
                fw.write(create_form)
            with open(
                    f'{target_path}/{model_name}List/components/UpdateForm.jsx',
                    'w') as fw:
                fw.write(update_form)