Merge pull request '前端动态获取主题' (#120) from KingChan/forgeplus:chenjing into standalone_develop

This commit is contained in:
KingChan
2023-08-24 15:03:42 +08:00
5 changed files with 39 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
class Admins::PageThemesController < Admins::Topic::BaseController
class Admins::PageThemesController < Admins::BaseController
before_action :finder_page_theme, only: [:edit, :update, :destroy]
def index
@@ -19,9 +19,9 @@ class Admins::PageThemesController < Admins::Topic::BaseController
def create
@page_theme = PageTheme.new update_params
binding.pry
if @page_theme.save
save_image_file(params[:image_url], @page_theme)
save_image_file(params[:image])
redirect_to admins_page_themes_path
flash[:success] = "新增主题成功"
else
@@ -58,4 +58,12 @@ class Admins::PageThemesController < Admins::Topic::BaseController
def update_params
params.require(:page_theme).permit(:language_frame, :name, :cate, :image_url, :clone_url)
end
def save_image_file(file)
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
file_path = Util::FileManage.source_disk_filename(@page_theme, "image")
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
Util.write_file(file, file_path)
end
end

View File

@@ -54,8 +54,10 @@ class SitePagesController < ApplicationController
end
def themes
data = YAML.load_file(Rails.root.join('config/admins', 'page_themes.yml'))
render_ok({themes:data[theme_params.downcase]})
# data = YAML.load_file(Rails.root.join('config/admins', 'page_themes.yml'))
# render_ok({themes:data[theme_params.downcase]})
data = PageTheme.where(language_frame:theme_params).order(order_index: :asc)
render_ok ({themes:data})
end
private