/// <summary> /// 头像字段处理 /// </summary> /// <param name="list"></param> /// <returns></returns> private List <KTResourceSimpleView> GetNewList(IEnumerable <KTResourceSimpleView> list) { List <KTResourceSimpleView> listNew = new List <KTResourceSimpleView>(); for (int i = 0; i < list.Count(); i++) { KTResourceSimpleView resource = list.ElementAt(i); resource.avatarUrl = KTUtils.GetAvatar2(resource); listNew.Add(resource); } return(listNew); }
public static string GetAvatar2(KTResourceSimpleView obj) { string txt = string.Empty; if (!string.IsNullOrEmpty(obj.avatarUrl)) { string[] arr = obj.avatarUrl.Split(new string[] { "+++" }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { return("/" + arr[1]); } } // 李 小利 返回:小利 if (!string.IsNullOrEmpty(obj.name)) { string _s = obj.name.Replace(" ", ""); txt = _s.Length <= 2 ? _s : _s.Substring(0, 2); } return("/img/svgAvatar?code=" + System.Web.HttpUtility.UrlEncode(txt) + "&fill=hsl%28180%2C70%25%2C80%25%29&stroke=hsl%28180%2C90%25%2C20%25%29"); }