/// <summary> /// 获取当前模板的主题配色 /// </summary> /// <returns></returns> private ThemeSetting GetCurrentThemeSetting() { ThemeSetting currentSetting = new ThemeSetting(); //内页面跟随首页配置的主题配色方案变化 string currentTempdate = System.IO.File.ReadAllText(this.Server.MapPath(_templatesettings));//读取当前应用的模板 TemplateSetting curTemplateObj = ParseFormJson <TemplateSetting>(currentTempdate); if (curTemplateObj != null) { if (System.IO.File.Exists(this.Server.MapPath(_themesettings))) { string currentTheme = System.IO.File.ReadAllText(this.Server.MapPath(_themesettings));//读取模板应用的主题配色列表 List <ThemeSetting> curThemeObjs = ParseFormJson <List <ThemeSetting> >(currentTheme); if (curThemeObjs != null) { var info = curThemeObjs.FirstOrDefault(a => a.templateId == curTemplateObj.Id);//取当前启用的模板对应的主题配色方案 if (null != info) { currentSetting = info; //ViewBag.WritingColor = info.writingColor; //ViewBag.SecondaryColor = info.secondaryColor; //ViewBag.MainColor = info.mainColor; //ViewBag.FrameColor = info.frameColor; //ViewBag.ClassifiedsColor = info.classifiedsColor; //ViewBag.TypeId = (CommonModel.ThemeType)info.typeId; } } } } return(currentSetting); }
/// <summary> /// 修改主题设置 /// </summary> /// <param name="templateId">当前启用的模板ID</param> /// <param name="id">主键ID</param> /// <param name="typeId">0、默认;1、自定义主题</param> /// <param name="MainColor">主色</param> /// <param name="SecondaryColor">商城辅色</param> /// <param name="WritingColor">字体颜色</param> /// <param name="FrameColor">边框颜色</param> /// <param name="ClassifiedsColor">边框栏颜色</param> /// <returns></returns> public JsonResult updateTheme(int templateId, long id, int typeId, string MainColor = "", string SecondaryColor = "", string WritingColor = "", string FrameColor = "", string ClassifiedsColor = "") { Theme mVTheme = new Theme() { ThemeId = id, TypeId = (Himall.CommonModel.ThemeType)typeId, MainColor = MainColor, SecondaryColor = SecondaryColor, WritingColor = WritingColor, FrameColor = FrameColor, ClassifiedsColor = ClassifiedsColor }; ThemeApplication.SetTheme(mVTheme); #region 保存当前主题配色设置[前端页面使用]且保存到主题配色的Json文件 ThemeSetting theme = new ThemeSetting() { classifiedsColor = mVTheme.ClassifiedsColor, frameColor = mVTheme.FrameColor, mainColor = mVTheme.MainColor, secondaryColor = mVTheme.SecondaryColor, themeId = mVTheme.ThemeId, typeId = mVTheme.TypeId, writingColor = mVTheme.WritingColor, templateId = templateId }; List <ThemeSetting> curThemeObjs = new List <ThemeSetting>(); string path = this.Server.MapPath(_themesettings); if (System.IO.File.Exists(path)) { string currentTheme = System.IO.File.ReadAllText(path);//读取当前模板应用的主题配色 curThemeObjs = ParseFormJson <List <ThemeSetting> >(currentTheme); if (curThemeObjs != null && curThemeObjs.Count > 0) { var info = curThemeObjs.FirstOrDefault(a => a.templateId == templateId); if (info != null) { curThemeObjs.Remove(info); } } } curThemeObjs.Add(theme); string fullName = this.Server.MapPath(_themesettings); string themeJson = ObjectToJson <List <ThemeSetting> >(curThemeObjs, Encoding.UTF8); using (var fs = new FileStream(fullName, FileMode.Create, FileAccess.Write)) { var buffer = System.Text.Encoding.UTF8.GetBytes(themeJson); fs.Write(buffer, 0, buffer.Length); } #endregion return(Json(new { status = 1 })); }
public async Task <ActionResult> DeleteConfirmed(int id) { ThemeSetting themeSetting = await db.ThemeSettings.FindAsync(id); db.ThemeSettings.Remove(themeSetting); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private static void ApplyTheme(ThemeSetting theme) { var environment = DependencyService.Get <IEnvironment>(); ResourceDictionary themeDict; SystemTheme systemTheme = environment.GetOperatingSystemTheme(); switch (theme) { case ThemeSetting.System: if (systemTheme == SystemTheme.Dark) { themeDict = new DarkTheme(); } else { themeDict = new LightTheme(); } break; case ThemeSetting.Light: themeDict = new LightTheme(); systemTheme = SystemTheme.Light; break; case ThemeSetting.Dark: themeDict = new DarkTheme(); systemTheme = SystemTheme.Dark; break; default: throw new NotImplementedException(); } var styleDict = new ElementStyles(); ICollection <ResourceDictionary> mergedDictionaries = currentApplication?.Resources.MergedDictionaries; if (mergedDictionaries != null) { mergedDictionaries.Clear(); mergedDictionaries.Add(themeDict); // Need to merge theme into style dict before adding as style dict depends on theme styleDict.MergedDictionaries.Add(themeDict); mergedDictionaries.Add(styleDict); // Just add font dict since it doesn't depend on any others mergedDictionaries.Add(new AppFonts()); } // Set system theme for platform-specific theming. environment.ApplyTheme(systemTheme); }
public async Task <ActionResult> Edit([Bind(Include = "ThemeSettingID,Name,Logo,Favicon")] ThemeSetting themeSetting) { if (ModelState.IsValid) { db.Entry(themeSetting).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(themeSetting)); }
public async Task <ActionResult> Create([Bind(Include = "ThemeSettingID,Name,Logo,Favicon")] ThemeSetting themeSetting) { if (ModelState.IsValid) { db.ThemeSettings.Add(themeSetting); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(themeSetting)); }
public Setting(string settingFile) { _settingFile = settingFile; Project = new ProjectSetting(); General = new GeneralSetting(); Interface = new InterfaceSetting(); Theme = new ThemeSetting(); Script = new ScriptSetting(); Log = new LogSetting(); ReadFromFile(); }
// GET: ThemeSettings/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ThemeSetting themeSetting = await db.ThemeSettings.FindAsync(id); if (themeSetting == null) { return(HttpNotFound()); } return(View(themeSetting)); }
public ThemeSettingsPartHandler(IWorkContextAccessor workContextAccessor) { _workContextAccessor = workContextAccessor; Filters.Add(new ActivatingFilter <ThemeSettingsPart>("Site")); Filters.Add(new TemplateFilterForPart <ThemeSettingsPart>("ThemeSettings", "Parts/ThemeSettings", "Theme Settings")); T = NullLocalizer.Instance; OnGetEditorShape <ThemeSettingsPart>((content, part) => { var workcontext = _workContextAccessor.GetContext(); var settings = part.For(workcontext.CurrentCulture); if (settings == null) { part.Culture = workcontext.CurrentCulture; return; } part.Culture = settings.Culture; part.HeaderLogo = settings.HeaderLogo; part.HeaderLogoUrl = settings.HeaderLogoUrl; part.FooterLogo = settings.FooterLogo; part.FooterLogoUrl = settings.FooterLogoUrl; part.FooterAudienceMessage = settings.FooterAudienceMessage; part.FooterCopyrightsMessage = settings.FooterCopyrightsMessage; part.PublishedDateText = settings.PublishedDateText; part.PublishedDateFormat = settings.PublishedDateFormat; part.LowercasePublishedDate = settings.LowercasePublishedDate; part.NonContentPublishedDateText = settings.NonContentPublishedDateText; part.NonContentReferenceNumber = settings.NonContentReferenceNumber; part.NonContentPreparationDateText = settings.NonContentPreparationDateText; part.CookiebarText = settings.CookiebarText; part.CookiebarYesText = settings.CookiebarYesText; part.CookiebarNoText = settings.CookiebarNoText; part.MemberLogo = settings.MemberLogo; part.ProviderLogo = settings.ProviderLogo; }); OnUpdateEditorShape <ThemeSettingsPart>((context, part) => { var workcontext = _workContextAccessor.GetContext(); bool isNew = false; var settings = part.For(workcontext.CurrentCulture); if (settings == null) { settings = new ThemeSetting(); isNew = true; } settings.Culture = part.Culture; settings.HeaderLogo = part.HeaderLogo; settings.HeaderLogoUrl = part.HeaderLogoUrl; settings.FooterLogo = part.FooterLogo; settings.FooterLogoUrl = part.FooterLogoUrl; settings.FooterAudienceMessage = part.FooterAudienceMessage; settings.FooterCopyrightsMessage = part.FooterCopyrightsMessage; settings.DisplayPublishedDate = part.DisplayPublishedDate; settings.PublishedDateText = part.PublishedDateText; settings.PublishedDateFormat = part.PublishedDateFormat; settings.LowercasePublishedDate = part.LowercasePublishedDate; settings.NonContentPublishedDateText = part.NonContentPublishedDateText; settings.NonContentReferenceNumber = part.NonContentReferenceNumber; settings.NonContentPreparationDateText = part.NonContentPreparationDateText; settings.CookiebarEnabled = part.CookiebarEnabled; settings.CookiebarText = part.CookiebarText; settings.CookiebarYesText = part.CookiebarYesText; settings.CookiebarNoText = part.CookiebarNoText; settings.MemberLogo = part.MemberLogo; settings.ProviderLogo = part.ProviderLogo; if (isNew) { part.All = new List <ThemeSetting>(part.All) { settings }; } else { var all = new List <ThemeSetting>(part.All); all.RemoveAll(x => x.Culture == part.Culture); all.Add(settings); part.All = all; } }); }
public ThemeService(ISettingService settingService) { _settingsService = settingService; _themeSetting = settingService.Get <ThemeSetting>(); UpdateTheme(); }