自定义组件的修正

表单组件html文件 index1.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />

    <style>
              /* 多图样式 */
    .flex {
        display: flex;
        flex-wrap: wrap;
    }
    .upzimgClass{
        height: 105px;
    }

    .clearfix:after {
        content: "";
        display: table;
        clear: both;
        visibility: hidden;
        width: 0;
        height: 0;
    }

    .uploadSource {
        width: 80px;
        height: 80px;
        line-height: 80px;
        margin-right: 10px;
        border: 1px dashed #ededed;
        text-align: center;
        color: #dad9d9;
        float: left;
        position: relative;
        cursor: pointer;
        background: white;
    }
    .uploadSource_img{
        width: 80px;
        height:80px;
    }
        .bkClass{
            background-color: #000!important;
        }
        .userp_1{
            position: relative;
        }
        .userp_2{
            position:absolute;
            right:20px;
            top:8px;
            font-weight: bold;
        }
        .layui-form-item .layui-form-label{
            width: 130px;
        }
        .layui-form-item .layui-input-block{
            margin-left: 160px;
      
        }
    </style>
       <script src="/static/user/js/jquery.min.js"></script>
       <script src="/static/component/layui/layui.js"></script>
       <script src="/static/component/pear/pear.js"></script>
</head>

<body>
    <form class="layui-form" action="javascript:;" id="formId">
      
        <div class="mainBox">
            <div class="main-container">
                {volist name="lst" id="vo" key="ksl_is"}
                {php} $Va=json_decode( $msg['content'],true );  {/php}
                <div class="layui-form-item" {if ($vo.type)*1 < 0} style="display:none;" {/if}>
                  <label class="layui-form-label">{$vo.label}</label>
                  <div class="layui-input-block userp_1">
                    {switch name="$vo.type"}
                        {case value="-1"}
                            <input type="hidden" name="{$vo.name}" value="{$Va[$vo['name']]|default=$vo.value}">
                        {/case}
                        {case value="0"}
                        <!-- 输入框输入 -->
     
                        <input type="text" name="{$vo.name}" value="{$Va[$vo['name']]|default=''}" required  lay-verify="required" placeholder="请输入{$vo.label}" autocomplete="off" class="layui-input">
                        <span class="userp_2">{$vo.unit}</span>
                        {/case}
                        {case value="1"}
                            <!-- 1 文本框 -->
                            <textarea name="{$vo.name}" autocomplete="off" class="layui-textarea" required
                            lay-verify="required" placeholder="请输入{$vo.label}">{$Va[$vo['name']]|default=''}</textarea>

                        {/case}
                        {case value="2"}
                            <!-- 富文本框 -->
                            <script 
                                id="{$vo.name}_ID" 
                                type="text/plain" 
                                style="width:300;height: 500px;"
                                name="{$vo.name}">
                            </script>
                            <script>
                                $(function(){
                                    var ue = UE.getEditor('{$vo.name}_ID', {
                                        autoFloatEnabled: false//是否保持toolbar位置不懂
                                    });
                                    "{if !empty($Va[$vo['name']])}"
                                        UE.getEditor('{$vo.name}_ID').addListener("ready", function () {
                                            UE.getEditor('{$vo.name}_ID').setContent(`{:html_entity_decode($Va[$vo['name']])}`, false);
                                        });
                                    "{/if}"
                                })
                            </script>
                        {/case}
                        {case value="2.1"}
                        <!-- 富文本框 -->
                        <script id="{$vo.name}_ID" type="text/plain" style="height:{$vo.height};" name="{$vo.name}"></script>
                        <script>
                            $(function () {
                                var ue = UE.getEditor('{$vo.name}_ID', {
                                    autoFloatEnabled: false//是否保持toolbar位置不懂
                                    ,toolbars:[[ 'Source', 'Undo', 'Redo','bold','test','underline','fontborder','strikethrough','superscript','subscript',
  
                                'removeformat', 'formatmatch' ,'autotypeset', 'blockquote', 'pasteplain', 'forecolor', 'backcolor',
  
                                'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']]
                                });
                                "{if !empty($Va[$vo['name']])}"
                                UE.getEditor('{$vo.name}_ID').addListener("ready", function () {
                                    UE.getEditor('{$vo.name}_ID').setContent(`{:html_entity_decode($Va[$vo['name']])}`, false);
                                });
                                "{/if}"
                            })
                        </script>
                        {/case}
                        {case value="3"}
                                <!-- 单选-->
                                {php}  
                                    $isv_checked="no_value";
                                    if(!empty( $Va[$vo['name']] )){
                                        $isv_checked=$Va[$vo['name']];
                                    }
                                {/php}
                              
                            {volist name="$vo.srcVal" id="vi" key="vi_s"}
                                <input type="radio" lay-filter="{$vo.name}" name="{$vo.name}" value="{$key}" title="{$vi}" {if $isv_checked == $key } checked {/if} {if $isv_checked=="no_value" && $vi_s == 1} checked {/if}>
                            {/volist}
                        {/case}
                        {case value="4"}
                                {php}  
                                    $isv_arr=[];
                                    if(!empty( $Va[$vo['name']] )){
                                        $isv_arr= json_decode($Va[$vo['name']],true);
                                    }
                                {/php}
                                <!-- 多选  -->
                                {volist name="$vo.srcVal" id="vi" key="vi_s"}
                                    <input type="checkbox" lay-filter="{$vo.name}" name="{$vo.name}[]" value="{$key}" title="{$vi}" {if in_array($key,$isv_arr) }checked {/if}>
                                {/volist}
                        {/case}
                        {case value="5"}
                             <!--自定义多值标签  -->
                             {php}  
                                $isv_arr=[];
                                if(!empty( $Va[$vo['name']] )){
                                    $isv_arr= json_decode($Va[$vo['name']],true);
                                }
                            {/php}
                            <div class="layui-btn-container tag tagClassCg" style="padding-top: 5px;" id="{$vo.name}Id" lay-filter="{$vo.name}Id"
                            lay-allowclose="true" lay-newTag="true">
                                {volist name="$isv_arr" id="ITP" key="ITPI"} 
                                <button lay-id="{$ITPI}" type="button" class="tag-item">{$ITP}</button>
                                {/volist}
                            </div>
                            <input type="hidden" name="{$vo.name}" value="" id="{$vo.name}Id_input">
                        {/case}
                        {case value="6"}
                            <!--单选下拉  -->
                            {php}  
                            $isv_checked="no_value";
                            if(!empty( $Va[$vo['name']] )){
                                $isv_checked=$Va[$vo['name']];
                            }
                        {/php}
                            <select name="{$vo.name}" {if !empty($vo.is_search)}  lay-search  {/if}>
                                <option value="">请选择{$vo.label}</option>
                                {volist name="$vo.srcVal" id="vi" key="vi_s"}
                                    <option value="{$key}" {if $isv_checked == $key } selected {/if}>{$vi}</option>
                                {/volist}
                            </select>
                        {/case}
                        {case value="7"}
                            <!--多选下拉  -->
                            {php}  
                                    $isv_arr=[];
                                    if(!empty( $Va[$vo['name']] )){
                                        $isv_arr=explode(",",$Va[$vo['name']]);
                                    }
                                {/php}
                            <select name="{$vo.name}" xm-select="{$vo.name}" xm-select-skin="{$vo.skin}"  xm-select-search="">
                                {volist name="$vo.srcVal" id="vi" key="vi_s"}
                                    <option value="{$key}" {if in_array($key,$isv_arr) }selected{/if}>{$vi}</option>
                                {/volist}
                            </select>
                        {/case}
                    
                        {case value="8"}
                            <!-- 单文件上传 -->
                            {if empty($Va[$vo['name']])}
                                <button  type="button" onclick="upFileClass('{$vo.name}')" class="tag-item tag-item-warm layui-btn layui-btn-default layui-btn-xs upFileClass upFileClass1_{$vo.name}" style="margin-top: 10px;">上传</button>
                                <a  style="margin-top: 10px;background-color:#36b368 !important;display: none;" plain class="upFileClass2_{$vo.name} tag-item tag-item-warm layui-btn layui-btn-default layui-btn-xs"
                                href=""  target="_blank" 
                                >下载</a>
                            {else/} 
                            <button type="button"   onclick="upFileClass('{$vo.name}')" style="margin-top: 10px;" class="tag-item tag-item-warm bkClass layui-btn layui-btn-default layui-btn-xs upFileClass upFileClass1_{$vo.name}"
                                >已上传</button>
                                <a  style="margin-top: 10px;background-color:#36b368 !important;" plain class="upFileClass2_{$vo.name}  tag-item tag-item-warm layui-btn layui-btn-default layui-btn-xs"
                                href="/static/files/runtimefile/{$Va[$vo['name']]}"  target="_blank"
                                >下载</a>
                            {/if}
                            <input name="{$vo.name}" onchange="keyfileId(this,'{$vo.name}')" type="file" style="display:none;" id="{$vo.name}Id">
                            <input name="{$vo.name}" type="hidden" value="{if empty($Va[$vo['name']])}{else/}{$Va[$vo['name']]}{/if}">
                        {/case}
                        {case value="9"}
                            <!-- 多文件上传 -->
                            <div style="padding-top:7px ;" class="Class_{$msg.Snt}_page_{$vo.name}_{$msg.id}">
                                <!-- 文件容纳盒子 -->
                            </div>
                            <button  type="button" onclick="upFileClassM('{$vo.name}')" class="tag-item tag-item-warm layui-btn layui-btn-default layui-btn-xs" style="margin-top: 10px;">上传</button>
                            <input name="{$vo.name}" value="{$msg.Snt}_page_{$vo.name}_{$msg.id}" type="hidden">

                            <script>
                                $(function(){
                                    getRuntimeimg_file('{$msg.Snt}_page_{$vo.name}_{$msg.id}',1);
                                });
                            </script>
                        {/case}
                        {case value="10"}
                            <!-- 单图片上传 -->
                            <div class="clearfix">
                                <div class="uploadSource_img uploadSource_img_{$vo.name}" onclick="uploadImg(this,'{$vo.name}')">
                                    {if empty($Va[$vo['name']])}
                                    <i class="pear-icon pear-icon-add-bold" style="font-size: 50px;line-height: 80px;"></i>
                                    {else/} 
                                    <img src="/static/files/runtimefile/{$Va[$vo['name']]}" style="width:80px;height:80px;">
                                    {/if}
                                </div>
  
                                <input type="file" class="fileUpdate_attrClass_{$vo.name}" onchange="fileUpdate_attrClassChange(this,'{$vo.name}')"  name="{$vo.name}" style="display:none;">
                                <input name="{$vo.name}" type="hidden" value="{if empty($Va[$vo['name']])}{else/}{$Va[$vo['name']]}{/if}">
                            </div>
                        {/case}
                        {case value="11"}
                            <!-- 多图片上传 -->
                            <div class="flex files_imgdivdir_t0 files_imgdivdir_t0_{$msg.Snt}_page_{$vo.name}_{$msg.id}" data-name="{$vo.name}" style="padding-bottom: 10px;">
                                <div class="clearfix">
                                    <div class="clearfix pull-left flex">
                                        <div class="flex"></div>
                                        <div class="uploadSource" onclick="upimgsru('{$vo.name}')" style="background: white;">
                                            <i class="pear-icon pear-icon-add-bold" style="font-size: 50px;"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <input name="{$vo.name}" value="{$msg.Snt}_page_{$vo.name}_{$msg.id}" type="hidden">
                            <script>
                                $(function(){
                                    getRuntimeimg('{$msg.Snt}_page_{$vo.name}_{$msg.id}',1);
                                });
                            </script>
                        {/case}
                        {case value="12"}
                        <!--开关切换  -->
                        {php}
                        $status = empty($Va[$vo['name']]) ? 0 : 1;
                        {/php}
                        <input type="checkbox" tname="{$vo.name}" value="1" lay-skin="switch" lay-filter="checkboxth-set"
                            lay-text="{$vo.srcVal}" {if $status} checked {/if} />
                        <input type="hidden" name="{$vo.name}" value="{$status}">
                        {/case}
                        {case value="13"}
                            {php}
                                $CHECKARR = empty($Va[$vo['name']]) ? [] : $vo['srcVal'][$Va[$vo['name']]];
                            {/php}
                            <button 
                                type="button" 
                                style="margin-top: 10px;" 
                                class="tag-item tag-item-warm  layui-btn layui-btn-default layui-btn-xs"
                                onclick="SelectEIdRt(this,'{$vo.pagetitle}','{$vo.selectpage}')"
                            >{if $CHECKARR}已选中|{$CHECKARR}{else/}未选中{/if}</button>
                            <input type="hidden" name="{$vo.name}" value="{if $CHECKARR}{$Va[$vo['name']]}{else/}0{/if}">
               
                        {/case}
                        {case value="14"}
                        <input type="text" name="{$vo.name}" id="ID-laydate-format-Class{$ksl_is}Id" value="{$Va[$vo['name']]|default=''}" required  lay-verify="required" placeholder="请输入{$vo.label}" autocomplete="off" class="layui-input ClassTimeYmd">
                        <span class="userp_2">{$vo.unit}</span>
                        {/case}

                    {/switch}
                  </div>
                </div>
                {/volist}

            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>


  
    <form style="display:none;" id="ajaxupimgfileId" method="post" enctype="multipart/form-data">
        <input type="file" name="img[]" id="imgfileinputId" multiple>
    </form>
 
    <script type="text/javascript" charset="utf-8" src="/static/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/editor/ueditor.all.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/static/editor/lang/zh-cn/zh-cn.js"></script>
    <!-- 单文件 -->
    {include file="component/FormConfig/file"} 
    <!-- 多文件 -->
    {include file="component/FormConfig/files"} 
    <!-- 单图 -->
    {include file="component/FormConfig/img"}
    <!-- 多图 -->
    {include file="component/FormConfig/imgs"}
    <script>
    

  

        layui.use(['table', 'form', 'jquery','tag','select','code','laydate'], function() {
            let $ = layui.jquery;
            let table = layui.table;
            let form = layui.form;
            let tag = layui.tag; 
            let select = layui.select; 
            var laydate = layui.laydate;
            // 自定义格式
            $(".ClassTimeYmd").each(function(){
                laydate.render({
                    elem: '#'+$(this).attr("id"),
                    format: 'yyyy-MM-dd'
                });
            });
          
            layui.code();
                   //checkboxth-set
                   //is_child
            form.on('switch(checkboxth-set)', function (obj) {
           
                var id = this.value;
                var status = obj.elem.checked ? 1 : 0;
                var statusInputName = obj.elem.attributes.tname.nodeValue;
                $(`input[name='${statusInputName}']`).val(status);
            });
            form.on('submit(form-save)', function (data) {
              $(".tagClassCg").each(function(){
                    //标签赋值

                    var jsonObj=[];
                    var id=$(this).attr("id");
                    $("#"+$(this).attr("id")).find(".tag-item").each(function(){

                        var str=$(this).text();

                        str=str.slice(0,-1);

                        jsonObj.push(str);

                    });

                    var jsonStr=JSON.stringify(jsonObj);

                    $(`#${id}_input`).val(jsonStr);
              });


                var data = $("#formId");
                postDatai("{:url('component/formConfigInsert')}?id={$msg.id}&active={$Origin}", data).then(function (res) {
                    if (res.code == 200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                        "{if !empty($is_child)}"
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("tableId");
                        "{/if}"
                           return; 
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });
     

        })
    </script>

{include file="base/footer"}
</body>

</html>

base.php控制器

<?php

namespace app\admin\controller;

use think\facade\{View, Session, Db};
use app\BaseController;
use think\exception\HttpResponseException;
class Base extends BaseController
{
    protected $Ajax=0; //0 跳转请求,1 ajax请求
    public function initialize()
    {
        parent::initialize();
        $this->Ajax = request()->isAjax() ? 1 : 0;
        if(!$this->isLogin()){
            if($this->Ajax){
                throw new HttpResponseException(returnmsg(-1,"登录超时"));
            }
            $this->redirectTo((string) url('login/login'));   
        }
    }
    private function isLogin(){
        return Session("lt_auser") ?? 0;
    }
    /**
     * 自定义重定向方法
     * @param $args
     */
    protected function redirectTo(...$args)
    {
        // 此处 throw new HttpResponseException 这个异常一定要写
        throw new HttpResponseException(redirect(...$args));
    }


    public function setStatus()
    {
        $data=[];
        $data[input('key')]=input('value');  
        $is = Db::name(input('table'))->where("id", input("id"))->update($data);
        return $is ? returnmsg(200, "操作成功") : returnmsg(199, "操作异常");
    }
    public function setTablesave(){
        if(input('type')<3){
            Db::name(input('table'))->where("id","in",trim(input("ids"),","))->update([
                'status'=> input('status'),
           
            ]);
        }elseif(input('type')==3){
            Db::name(input('table'))->where("id","in",trim(input("ids"),","))->delete();
            if(input('table')=="iuser"){
                Db::name("iuser_balance")->where("iuser_id","in",trim(input("ids"),","))->delete();
            }
        }
    
        return returnmsg(200,"操作成功");
    }

    // 菜单menujson
    public function menujson(){
        $mp=[];
        if(Session('lt_auser')['id']!=1){
          $role_id=Session('lt_auser')['role_id'];
          //Db::name("limit_operate")->column();
          $limits= json_decode(Db::name("role_user")->where("id",$role_id)->value("limits"),true);
          $mp[]=["id","in",$limits];
        }
          $lst=Db::name("limit_operate")->field("id,title,icon,type,url href,openType")->where($mp)->where("pid",0)->where("status",1)->order("xh asc")->select()->toArray();
  
          foreach($lst as &$v){
      
            $v['icon']="layui-icon ".$v['icon'];
            $v['children']=Db::name("limit_operate")->where($mp)->field("id,title,icon,type,url href,openType")->where("pid",$v['id'])->where("status",1)->order("xh asc")->select()->toArray();
            if(!$v['children']){
                unset($v);
            }
          }
          return json($lst);
 
      }







//-----------------组件化









          // 自定义php-v 组件方法  -- 组件名 与 所需数据
    protected function ComponentSrc($Component_name,$data){
        //Itemtitle
        switch($Component_name){
            // 弹框内的-类下拉组件
            case 'SelectHtml':
                // data 参数  t1   t2   lst=[]
                View::assign("msg",[
                    "Thtitle"=>$data['t1'],
                    "Itemtitle"=>$data['t2'],
                ]);
                View::assign("lst",$data['lst']);

                break;
                // 表单集合器
            case 'FormConfig':
                //t1:标题
                //lst:二维数组  :[[ 单位:unit:""  type:0 输入框 1 文本框 2 富文本  3,单选  4, 多选  5,多选自定义输入  6 单选下拉列表  7 多选下拉列表    8 文件上传  9 多文件上传  10单图上传 11 多图上传 ,label:标题  ]]
                View::assign("pagetitle",$data['t1']);
                View::assign("lst",$data['lst']);
                View::assign("Origin",$data['Origin']);
                View::assign("is_child",empty($data['is_child']) ? 0 : 1 );
                if($data['Origin']){
                  
                    $arns=explode("__",$data['Origin']);
                    $msg['Snt']=$data['Snt'];
                    if($arns[1]==0){
                        //若是要新增数据
                        $msg=Db::name("config_content")->where("Snt",$data['Snt'])->find();
                        if(!$msg){
                            //若是新增结构
                            Db::name("config_content")->insert([
                                'Snt'=>$data['Snt'],
                                'title'=>$data['t1'],
                                'content'=>'{}'
                            ]);  
                            $msg=Db::name("config_content")->where("Snt",$data['Snt'])->find();
                        }
                        $msg['id']=uniqid();
                    }else{
                        $mstn=Db::name($arns[0])->find($arns[1]);
                        $msg['content']=json_encode($mstn);
                        $msg['id']=$mstn['gi_dir'];//重新指向数据文件路径--还是要从源头出发
              
                    }
                  
                    ////--多图片 多文件上传 要随机文件路径,
                    //$msg['id']=$msg['Snt'];//重新指向数据文件路径

                    //lsrp_page_openId=`{$msg.Snt}_page_${name}_{$msg.id}`;
                  
                }else{
                    $msg=Db::name("config_content")->where("Snt",$data['Snt'])->find();
                    if(!$msg){
                        Db::name("config_content")->insert([
                            'Snt'=>$data['Snt'],
                            'title'=>$data['t1'], 
                            'content'=>'{}'
                        ]); 
                        $msg=Db::name("config_content")->where("Snt",$data['Snt'])->find();
                    }
                }
      
                View::assign("msg",$msg);
                //dump($msg);
              

                break;
             //统计表集合器
             case 'Charjs':
                // foreach($data['lst'] as &$v){
                //     switch($v['type']){
                //         case 1:
                      
                //         break;
                //         case 1:
                //             break;
                //             case 1:
                //                 break;
                //                 case 1:
                //                     break;
                //                     case 1:
                //                         break;
                //     }
                // }
                View::assign("charData",$data['lst']);
              
                break;

            case 'Other':

                break;
          
        }
        return View::fetch("component/$Component_name/index".( !empty($data['_model'])  ? 1 : ""));
    
    }
    protected function setFiles($eId){
        Db::name("runtimefile")->where("eId",$eId)->where("is_useful",1)->delete();
        Db::name("runtimefile")->where("eId",$eId)->where("aid",Session("lt_auser")['id'])->update([
            'is_useful'=>1
        ]);
        return returnmsg(200,"已设置正式");
    }

}

组件控制器 Component.php

<?php

namespace app\admin\controller;

use think\facade\{View, Session, Db};
use app\BaseController;

class Component extends Base
{
    private $imggoodsruntime="runtimefile";

    //------------- 多图片处理-增删改查
      //快照缓存图片的添加
      public function spuimgruntimeinsert()
      {
          //图片上传
          $files = input('file.file');
          if(!$files){
            $files = input('file.img');
          }
  
          $param = input('param.');
          //本地添加
          if ($files) {
              foreach ($files as $file) {
                  $path = $this->imggoodsruntime;
                  $filename = uniqid() . ".".$file->extension();
                  \think\facade\Filesystem::disk('files')->putFileAs($path, $file, $filename);
                  $data = [];
                  $mp = [];
                  $mp['eId'] = $param['eId'];
                  $mp['type'] = $param['type'];
  
                  $data['xh'] = Db::name("runtimefile")->where($mp)->count();
                  $data['eId'] = $param['eId'];
                  $data['img'] = $filename;
                  $data['type'] = $param['type'];
                  $data['time'] = date("Y-m-d H:i:s");
                  $data['is_useful']=0;
                  $data['aid']=Session("lt_auser")['id'];
                  $data['remark']= $file->getOriginalName();
                  $insert = Db::name("runtimefile")->insert($data);
              }
          }
          return returnmsg(200, "操作成功");
      }
      //快照缓存图片的抓取
      public function getruntimeimg()
      {
        $mp=input('param.');
        // if(!input('is_useful')){
        //     $mp['aid']=Session("lt_auser")['id'];
        // }
        unset($mp['is_useful']);
        $data = Db::name("runtimefile")->field("id,eId,img,type,xh,remark")->where($mp)->order("xh asc")->select()->toArray();

        // 启动事务
        // Db::startTrans();
        // try {
        //     if(input('is_useful')){
        //         $mp['is_useful']=0;
        //         $mp['aid']=Session("lt_auser")['id'];
        //         Db::name("runtimefile")->where($mp)->delete();
        //         if($data){
        //             foreach($data as &$v){
        //                 $v['aid']=Session("lt_auser")['id'];
        //                 $v['is_useful']=0;
        //                 unset($v['id']);
        //             }
        //             Db::name("runtimefile")->insertAll($data);
        //             $data=Db::name("runtimefile")->where($mp)->order("xh asc")->select()->toArray();
        //         }
           
        //     }
        //       // 提交事务
        //     Db::commit();
        // } catch (\Exception $e) {
        //     // 回滚事务
        //     Db::rollback();
        // }

        return returnmsg(200, "检索成功", $data);
      }
      //快照图片排序删除操作
      public function setspuremove()
      {
          $post = input('post.');
          //print_r($post);
          //die;
          switch ($post['utys']) {
              case 'left':
                  $xh = $post['xh'] - 1;
                  //前面的不变,后面的不变,变中间
                  $mp = [];
                  $mp['xh'] = $xh;
                  $mp['eId'] = $post['eId'];
                  $mp['type'] = $post['type'];
                  $mp['is_useful']=0;
                  $mp['aid']=Session("lt_auser")['id'];
                  //$mp['id']=$post['id'];
                  Db::name('runtimefile')->where($mp)->update(array('xh' => $post['xh']));
                  Db::name('runtimefile')->where('id', $post['id'])->update(array('xh' => $xh));
                  break;
              case 'right':
                  $xh = $post['xh'] + 1;
                  $mp = [];
                  $mp['xh'] = $xh;
                  $mp['eId'] = $post['eId'];
                  $mp['type'] = $post['type'];
                  $mp['is_useful']=0;
                  $mp['aid']=Session("lt_auser")['id'];
                  //$mp['id']=$post['id'];
                  Db::name('runtimefile')->where($mp)->update(array('xh' => $post['xh']));
                  Db::name('runtimefile')->where('id', $post['id'])->update(array('xh' => $xh));
                  break;
              case 'del':
                  $img = Db::name('runtimefile')->where('id', $post['id'])->value('img');
                  $del = Db::name('runtimefile')->delete($post['id']);
                 // $is = Db::name('runtimefile')->where('img', $img)->count();
                  $mp = [];
                  $mp['eId'] = $post['eId'];
                  $mp['type'] = $post['type'];
                  $mp['is_useful']=0;
                  $mp['aid']=Session("lt_auser")['id'];
                  $li = Db::name('runtimefile')->where($mp)->field('id,xh')->order('xh')->select()->toArray();
                  foreach ($li as $key => &$value) {
                      $value['xh'] = $key;
                  }
                  $model = new \app\admin\model\Runtimefile();
  
                  $up = $model->saveAll($li);
                  break;
              default:
                  # code...
                  break;
          }
          return returnmsg(200, "操作成功");
      }
       //   formConfig 配置 提交-更新
    public function formConfigInsert(){
        $param=input('param.');
        $files=input('file.');
  
        if($param){
            foreach($param as $key => $value){
                if(is_array($value)){
                    $param[$key]=json_encode($value);
                }
            }
        }
        if($files){
            foreach($files as $key => $file){
                if($_FILES[$key]['size']){
                    // 头图
                    $file = request()->file($key);
                    $param[$key] = uniqid() .".".$file->extension();
                    \think\facade\Filesystem::disk('files')->putFileAs($this->imggoodsruntime,$file, $param[$key]);
                }
            }

        }
   
        $this->setFiles("Wxconfig_page_webimgs_1");
        $this->setFiles("Wxconfig_page_webfiles_1");
        //active -  数据是否是指定表 的数据
        if(!input('active')){
            Db::name("config_content")->where("id",input('id'))->update([ 'content'=>json_encode( $param ) ]);
        }else{
           // Db::name("config_content")->where("id",input('id'))->update([ 'content'=>json_encode( $param ) ]);
            $arns=explode("__",input('active'));
            unset($param['id']);
            if($arns[1]!=0){
                $param['id']=$arns[1];
            }else{
                $param['addtime']=time();
                $param['gi_dir']=input('id',0);
            }
            $arrFieldArr=_tplFormFieldArr;
            if($arrFieldArr){
                foreach($arrFieldArr as $v){
                    if($v['table']==$arns[0]){
                        switch($v['type']){
                            case 'uniqid':
                                $mp = [];
                                $mp[] =!empty($param['id'])  ? ["id", "<>", $param['id']] : ["id", ">", 0];
                                $is = Db::name($arns[0])->where($mp)->where($v['field'], $param[$v['field']])->value("id");
                                if ($is) {
                                    return returnmsg(201, "用户名不能重复");
                                }  
                            break;
                        }

                    }
                }
            }
          
       
           //$param['id']==  id 有值更新 ----无值新增
           Db::name($arns[0])->strict(false)->save($param);
        }
      

        return returnmsg(200,"操作成功");

      
    }
  
  


}