<?php

namespace app\admin\controller;

use app\model\UploadFiles;
use app\UploadFiles as AppUploadFiles;
use think\facade\View;
use think\Request;

class File extends Common
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //

        $type = $this->request->param('type', 1);
        $status = $this->request->param('status', '');

        $model_list = UploadFiles::withTrashed()->where('type', $type)->order('id desc');

        if ($status != '') {
            $model_list->where('status', $status);
        }

        $list = $model_list->paginate();
        View::assign('list', $list);

        return View::fetch();
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //

        return AppUploadFiles::save($request);
    }

    public function editormdSave(Request $request)
    {
        return AppUploadFiles::editormdSave($request);
    }
    public function wangEditorSave(Request $request)
    {
        return AppUploadFiles::wangEditorSave($request);
    }

    public function urlSave(Request $request)
    {
        return AppUploadFiles::saveUrlFile($request->param('url'), $request->param('type'));
    }

    public function base64Save(Request $request)
    {
        return AppUploadFiles::saveBase64File($request->param('data'), $request->param('type'));
    }

    public function clear($id)
    {
        AppUploadFiles::clear($id);

        return json_message();
    }
}
