Exemplo n.º 1
0
 private static void InitRenderOptions(VxeRender itemRender, ComboboxAttribute comboAttr)
 {
     itemRender.Options = WebConsts
                          .GetComboboxDataFunc(comboAttr.Type.Name, comboAttr.WhereField, comboAttr.WhereOper,
                                               comboAttr.WhereValue, comboAttr.DisplayField).ConfigureAwait(false).GetAwaiter().GetResult()
                          .Select(x => new LabelValue(x.Key, x.Value)).ToList();
 }
Exemplo n.º 2
0
        static string GetRender(VxeRender render)
        {
            var html = new StringBuilder();

            var tagName = "";

            switch (render.Name)
            {
            case VxeConsts.RenderName_Input:
                tagName = VxeConsts.TagName_Input;
                break;

            case VxeConsts.RenderName_TextArea:
                tagName = VxeConsts.TagName_TextArea;
                break;

            case VxeConsts.RenderName_Switch:
                tagName = VxeConsts.TagName_Switch;
                break;

            case VxeConsts.RenderName_Iview_Select:
                tagName = VxeConsts.TagName_Iview_Select;
                break;

            case VxeConsts.RenderName_Iview_TimePicker:
                tagName = VxeConsts.TagName_Iview_TimePicker;
                break;

            case VxeConsts.RenderName_Iview_DatePicker:
                tagName = VxeConsts.TagName_Iview_DatePicker;
                break;
            }

            html.Append($"<{tagName} ");

            foreach (var @event in render.Events)
            {
                html.Append($" @{@event.Key}=\"{@event.Value}\" ");
            }

            foreach (var prop in render.Props)
            {
                html.Append(GetAttr(prop.Key, prop.Value));
            }
            html.Append(" >");

            if (render.Options != null)
            {
                foreach (var x in render.Options)
                {
                    var pre       = "";
                    var valueType = x.Value.GetType();
                    var isbool    = valueType == typeof(bool);
                    if (isbool || valueType.IsNumberType())
                    {
                        pre = ":";
                        if (isbool)
                        {
                            x.Value = x.Value.ToString().ToCamelCase();
                        }
                    }

                    html.Append($"<i-option {pre}value=\"{x.Value}\" key=\"{x.Value}\">{x.Label}</i-option>");
                }
            }

            html.Append(render.Html);

            html.Append($"</{tagName}>");

            return(html.ToString());
        }
Exemplo n.º 3
0
        private static void InitRender(Type type, VxeRender itemRender, PropertyInfo property)
        {
            var attributes   = property.GetCustomAttributes(true);
            var propertyType = property.PropertyType;
            var valueType    = propertyType.GetValueType();
            var comboboxAttr = GetAttribute <ComboboxAttribute>(attributes);
            var isEnum       = valueType.IsEnum;
            var isCombo      = comboboxAttr != null || valueType.IsEnum;

            if (isCombo)
            {
                itemRender.Name = VxeConsts.RenderName_Iview_Select;
                itemRender.Props.Add("clearable", true);

                bool isFilter = true;
                if (isEnum)
                {
                    isFilter           = false;
                    itemRender.Options = EnumUtil.GetEnumValueList(valueType).Select(x => new LabelValue(x.Key, x.Value))
                                         .ToList();
                }
                else if (comboboxAttr != null)
                {
                    if (comboboxAttr.IsLoadData)
                    {
                        var comboAttr = GetAttribute <ComboboxAttribute>(attributes);

                        if (comboAttr != null && comboAttr.IsLoadData)
                        {
                            var selectDictionary = _typeSelectDictionary.GetOrDefault(type) ??
                                                   new Dictionary <string, ComboboxAttribute>();
                            selectDictionary.Add(property.Name, comboAttr);
                            if (!_typeSelectDictionary.ContainsKey(type))
                            {
                                _typeSelectDictionary.TryAdd(type, selectDictionary);
                            }
                        }
                    }
                }

                if (comboboxAttr?.IsReadOnly.HasValue == true)
                {
                    isFilter = comboboxAttr.IsReadOnly.Value;
                }

                if (isFilter)
                {
                    itemRender.Props.Add("filterable", true);
                }
            }
            else if (propertyType.IsNumberType())
            {
                var numberType = "number";
                if (!new[] { typeof(int), typeof(long) }.Contains(valueType))
                {
                    numberType = "float";
                    var precisionAttr = GetAttribute <NumberFormatAttribute>(attributes);
                    if (precisionAttr != null)
                    {
                        itemRender.Props.Add("digits", precisionAttr.Precision);
                    }
                }

                itemRender.Props.Add("type", numberType);

                var rangeAttr = GetAttribute <RangeAttribute>(attributes);
                if (rangeAttr != null)
                {
                    itemRender.Props.Add("min", rangeAttr.Minimum);
                    itemRender.Props.Add("max", rangeAttr.Maximum);
                }
                else
                {
                    itemRender.Props.Add("min", 0);
                }
            }
            else if (valueType == typeof(DateTime))
            {
                var datetimeAttr   = GetAttribute <DateFormatAttribute>(attributes);
                var datePickerType = VxeConsts.RenderName_Iview_DatePicker;
                var dateType       = "date";
                //itemRender.Props.Add("transfer", true);
                if (datetimeAttr != null)
                {
                    if (datetimeAttr.DateFormatString.StartsWith("HH"))
                    {
                        datePickerType = VxeConsts.RenderName_Iview_TimePicker;
                    }
                    else if (datetimeAttr.DateFormatString.Contains("HH"))
                    {
                        dateType = "datetime";
                    }

                    itemRender.Props.Add("format", datetimeAttr.DateFormatString);
                }

                if (datePickerType == VxeConsts.RenderName_Iview_DatePicker)
                {
                    itemRender.Props.Add("type", dateType);
                }

                itemRender.Name = datePickerType;
            }
            else if (propertyType.GetValueType() == typeof(bool))
            {
                itemRender.Name = VxeConsts.RenderName_Switch;
                itemRender.Props.Add("onLabel", "是");
                itemRender.Props.Add("offLabel", "否");
            }
        }