|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
- <title>修改栏目</title>
- <link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
- <link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
- <link rel="stylesheet" href="/static/web/css/admin.css">
- <script src="/static/web/js/jquery.min.js"></script>
- <script src="/static/web/js/bootstrap.min.js"></script>
- <script src="/static/web/js/admin.main.js"></script>
- </head>
- <body>
- <div class="container-fluid">
- <ol class="breadcrumb">
- <li class="breadcrumb-item"><a href="index_body.php">后台面板</a></li>
- <li class="breadcrumb-item"><a href="catalog_main.php">网站栏目管理</a></li>
- <li class="breadcrumb-item active">修改栏目</li>
- </ol>
- <div class="card shadow-sm">
- <div class="card-header d-flex justify-content-between align-items-center">修改栏目<?php if($cfg_ai_enabled == 'Y'){;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">小德AI助手</button><?php };?></div>
- <div class="card-body">
- <form name="form1" action="catalog_edit.php" method="post">
- <input type="hidden" name="dopost" value="save">
- <input type="hidden" name="id" value="<?php echo $id;?>">
- <input type="hidden" name="topid" value="<?php echo $myrow['topid'];?>">
- <div class="table-responsive">
- <table class="table table-borderless">
- <tbody>
- <tr>
- <td width="10%">是否支持投稿</td>
- <td width="40%">
- <label><input type="radio" name="issend" value="1" <?php if ($myrow['issend']=="1") echo 'checked';?>> 支持</label>
- <label><input type="radio" name="issend" value="0" <?php if ($myrow['issend']=="0") echo 'checked';?>> 不支持</label>
- </td>
- <td width="10%">是否隐藏栏目</td>
- <td width="40%">
- <label><input type="radio" name="ishidden" value="0" <?php if ($myrow['ishidden']=="0") echo 'checked';?>> 显示</label>
- <label><input type="radio" name="ishidden" value="1" <?php if ($myrow['ishidden']=="1") echo 'checked';?>> 隐藏</label>
- </td>
- </tr>
- <tr>
- <td>文档模型</td>
- <td>
- <input type="hidden" value="{style}" name="dfstyle">
- <select name="channeltype" id="channeltype" onChange="ParTemplet(this);" class="admin-input-sm">
- <?php
- foreach($channelArray as $k=>$arr)
- {
- if ($k==$channelid) echo " <option value='{$k}' selected>{$arr['typename']} {$arr['nid']}</option>";
- else echo " <option value='{$k}'>{$arr['typename']} {$arr['nid']}</option>";
- }
- ?>
- </select>
- <div id="smclass" class="mt-2" style="<?php echo ($channelid<0 ? '' : 'display:none');?>">
- <select name="smalltype[]" multiple="yes" class="admin-input-lg">
- <?php
- $smtypes = explode(',',trim($myrow['smalltypes']));
- $sql = "SELECT * FROM `#@__sys_enum` WHERE egroup LIKE 'infotype' ORDER BY disorder ASC,evalue ASC ";
- $dsql->Execute('s',$sql);
- while($arr = $dsql->GetArray('s'))
- {
- if (in_array($arr['evalue'],$smtypes)) {
- $selstr = " selected='1' ";
- } else {
- $selstr = '';
- }
- if ($arr['evalue']%500==0) {
- echo "<option value='{$arr['evalue']}'{$selstr}>{$arr['ename']}</option>";
- } else if (preg_match("#\.#", $arr['evalue'])) {
- echo "<option value='{$arr['evalue']}'{$selstr}>└── {$arr['ename']}</option>";
- } else {
- echo "<option value='{$arr['evalue']}'{$selstr}>└─ {$arr['ename']}</option>";
- }
- }
- ?>
- </select>
- <span>(请选栏目的信息联动类型支持多选)</span>
- </div>
- </td>
- <td>上级目录</td>
- <td>
- <?php
- $pardir = '{cmspath}'.$cfg_arcdir;
- if (!empty($typedir)) $pardir = $typedir.'/';
- $pardir = preg_replace("#\/{1,}#", '/', $pardir);
- echo $pardir;
- ?>
- <input type="hidden" name="nextdir" id="nextdir" value="<?php echo $pardir?>">
- </td>
- </tr>
- <tr>
- <td>中文名称</td>
- <td><input type="text" name="typename" value="<?php echo $myrow['typename']?>" class="admin-input-lg" required></td>
- <td>中文概述</td>
- <td><input type="text" name="cnoverview" value="<?php echo $myrow['cnoverview']?>" class="admin-input-lg"></td>
- </tr>
- <tr>
- <td>英文名称</td>
- <td><input type="text" name="enname" value="<?php echo $myrow['enname']?>" class="admin-input-lg"></td>
- <td>英文概述</td>
- <td><input type="text" name="enoverview" value="<?php echo $myrow['enoverview']?>" class="admin-input-lg"></td>
- </tr>
- <tr>
- <td>栏目大图</td>
- <td>
- <input type="text" name="bigpic" value="<?php echo $myrow['bigpic']?>" class="admin-input-lg">
- <button type="button" class="btn btn-success btn-sm" onclick="SelectImage('form1.bigpic');">选择</button>
- </td>
- <td>栏目小图</td>
- <td>
- <input type="text" name="litimg" value="<?php echo $myrow['litimg']?>" class="admin-input-lg">
- <button type="button" class="btn btn-success btn-sm" onclick="SelectImage('form1.litimg');">选择</button>
- </td>
- </tr>
- <tr>
- <td>排列顺序</td>
- <td><input type="text" name="sortrank" value="<?php echo $myrow['sortrank']?>" class="admin-input-sm">(由低到高)</td>
- <td>浏览权限</td>
- <td>
- <select name="corank" id="corank" class="admin-input-sm">
- <?php
- $dsql->SetQuery("SELECT * FROM `#@__arcrank` WHERE `rank` >= 0 ORDER BY `rank` ASC");
- $dsql->Execute('cc');
- while($row = $dsql->GetObject('cc'))
- {
- if ($myrow['corank']==$row->rank)
- echo "<option value='".$row->rank."' selected>".$row->membername."</option>";
- else
- echo "<option value='".$row->rank."'>".$row->membername."</option>";
- }
- ?>
- </select>
- <span>(暂不支持静态)</span>
- </td>
- </tr>
- <tr>
- <td>栏目生成目录</td>
- <td><input type="text" name="typedir" id="typedir" value="<?php echo $myrow['typedir']?>" class="admin-input-lg"></td>
- <td>是否继承选项</td>
- <td><label><input type="checkbox" name="upnext" id="upnext" value="1"> 子类栏目继承顶级栏目的浏览权限、文档类型、模板风格等属性</label></td>
- </tr>
- <tr>
- <td>栏目列表选项</td>
- <td>
- <label><input type="radio" name="isdefault" value="1" <?php if ($myrow['isdefault']==1) echo 'checked';?>> 静态浏览</label>
- <label><input type="radio" name="isdefault" value="-1" <?php if ($myrow['isdefault']==-1) echo 'checked';?>> 动态浏览</label>
- <label><input type="radio" name="isdefault" value="0" <?php if ($myrow['isdefault']==0) echo 'checked';?>> 列表第一页浏览</label>
- </td>
- <td>默认页的名称</td>
- <td><input type="text" name="defaultname" value="<?php echo $myrow['defaultname']?>" class="admin-input-lg"></td>
- </tr>
- <tr>
- <td>栏目属性</td>
- <td>
- <label><input type="radio" name="ispart" value="0" <?php if ($myrow['ispart']==0) echo 'checked';?>> 列表栏目(允许发布)</label>
- <label><input type="radio" name="ispart" value="1" <?php if ($myrow['ispart']==1) echo 'checked';?>> 封面栏目(不允许发布)</label>
- <label><input type="radio" name="ispart" value="2" <?php if ($myrow['ispart']==2) echo 'checked';?>> 外部栏目(栏目生成目录填写链接)</label>
- </td>
- <td>栏目交叉</td>
- <td>
- <label><input type="radio" name="cross" id="cross0" value="0" onclick="CheckCross();" <?php if ($myrow['cross']==0) echo 'checked';?>> 不交叉</label>
- <label><input type="radio" name="cross" id="cross1" value="1" onclick="CheckCross();" <?php if ($myrow['cross']==1) echo 'checked';?>> 自动获取同名栏目</label>
- <label><input type="radio" name="cross" id="cross2" value="2" onclick="CheckCross();" <?php if ($myrow['cross']==2) echo 'checked';?>> 指定交叉栏目id(英文逗号隔开)</label>
- <a href="javascript:ShowHide('helpvarco');" class="btn btn-success btn-sm">说明</a>
- <div id="crossid" style="<?php if ($myrow['cross']!=2) echo'display:none';?>"><textarea name="crossid" class="admin-textarea-sm"><?php echo $myrow['crossid'];?></textarea></div>
- <div id="helpvarco" class="alert alert-secondary my-2" style="display:none">交叉栏目该栏目与另一个非子栏目交叉的情况,相当于副栏目功能</div>
- </td>
- </tr>
- <tr>
- <td width="260">多站点支持</td>
- <td>
- <label><input type="radio" name="moresite" value="1" <?php if ($myrow['moresite']==1) echo 'checked';?>> 启用</label>
- <label><input type="radio" name="moresite" value="0" <?php if ($myrow['moresite']==0) echo 'checked';?>> 不启用</label>
- <span>(仅顶级栏目启用,子类栏目无效)</span>
- </td>
- <td>绑定域名</td>
- <td><input type="text" name="siteurl" id="siteurl" value="<?php echo $myrow['siteurl']?>" class="admin-input-lg">(请输入绑定域名http开头)</td>
- </tr>
- <tr>
- <td>列表模板</td>
- <td>
- <input type="text" name="templist" value="<?php echo $myrow['templist']?>" class="admin-input-lg">
- <button type="button" class="btn btn-success btn-sm" onclick="SelectTemplets('form1.templist')">选择</button>
- </td>
- <td>封面模板</td>
- <td>
- <input type="text" name="tempindex" value="<?php echo $myrow['tempindex']?>" class="admin-input-lg">
- <button type="button" class="btn btn-success btn-sm" onclick="SelectTemplets('form1.tempindex')">选择</button>
- <a href="javascript:ShowHide('helpvar1');" class="btn btn-success btn-sm">说明</a>
- <div id="helpvar1" class="alert alert-secondary my-2" style="display:none">
- <p>{tid} 栏目id</p>
- <p>{cid} 栏目模型名字id</p>
- </div>
- </td>
- </tr>
- <tr>
- <td>文档模板</td>
- <td>
- <input type="text" name="temparticle" value="<?php echo $myrow['temparticle']?>" class="admin-input-lg">
- <button type="button" class="btn btn-success btn-sm" onclick="SelectTemplets('form1.temparticle')">选择</button>
- </td>
- <td>列表命名规则</td>
- <td>
- <input type="text" name="namerule2" id="namerule2" value="<?php echo $myrow['namerule2']?>" class="admin-input-lg">
- <a href="javascript:ShowHide('helpvar2');" class="btn btn-success btn-sm">说明</a>
- <div id="helpvar2" class="alert alert-secondary my-2" style="display:none">
- <p>静态规则</p>
- <p>{tid} 栏目id</p>
- <p>{page} 栏目页码数</p>
- <p>伪静态规则(Nginx)</p>
- <p>rewrite ^/list-([0-9]+)$ /apps/list.php?tid=$1;</p>
- <p>rewrite ^/list-([0-9]+)-([0-9]+)$ /apps/list.php?tid=$1&PageNo=$2;</p>
- </div>
- </td>
- </tr>
- <tr>
- <td>文档命名规则</td>
- <td>
- <input type="text" name="namerule" id="namerule" value="<?php echo $myrow['namerule']?>" class="admin-input-lg">
- <a href="javascript:ShowHide('helpvar3');" class="btn btn-success btn-sm">说明</a>
- <div id="helpvar3" class="alert alert-secondary my-2" style="display:none">
- <p>静态规则</p>
- <p>{Y}{M}{D} 年月日</p>
- <p>{timestamp} INT类型的UNIX时间戳</p>
- <p>{aid} 文档id</p>
- <p>{pinyin} 拼音加文档id</p>
- <p>{py} 拼音部首加文档id</p>
- <p>{typedir} 栏目保存目录</p>
- <p>{cc} 日期加混编id后用转换为适合字母</p>
- <p>伪静态规则(Nginx)</p>
- <p>rewrite ^/article/([0-9]+).html$ /apps/view.php?arcID=$1;</p>
- <p>rewrite ^/article/([0-9]+)-([0-9]+).html$ /apps/view.php?aid=$1&pageno=$2;</p>
- </div>
- </td>
- <td>SEO标题</td>
- <td><input type="text" name="seotitle" id="seotitle" value="<?php echo $myrow['seotitle']?>" class="admin-input-lg">(标签{dede:field.seotitle/}调用)</td>
- </tr>
- <tr>
- <td>关键词</td>
- <td>
- <textarea name="keywords" cid="keywords" class="admin-textarea-sm"><?php echo $myrow['keywords']?></textarea>
- <span>(标签{dede:field.keywords/}调用)</span>
- </td>
- <td>描述</td>
- <td>
- <textarea name="description" id="description" class="admin-textarea-sm"><?php echo $myrow['description']?></textarea>
- <span>(标签{dede:field.description/}调用)</span>
- </td>
- </tr>
- <tr>
- <td>栏目文档</td>
- <td>(标签{dede:field.content/}调用)</td>
- <td>是否支持跨站调用</td>
- <td>
- <input value="<?php echo $myrow['apikey']?>" type="text" name="apikey" id="apikey" class="admin-input-lg" placeholder="请输入跨站调用秘钥">
- <label><input type="radio" name="apienabled" value="1" <?php if ($myrow['apienabled']=="1") echo 'checked';?>> 支持</label>
- <label><input type="radio" name="apienabled" value="0" <?php if ($myrow['apienabled']=="0") echo 'checked';?>> 不支持</label>
- <a href="javascript:makeAPIKey();" class="btn btn-success btn-sm">更新</i></a>
- <a href="javascript:showAPI(<?php echo $id;?>);" class="btn btn-success btn-sm">说明</a>
- </td>
- </tr>
- <tr>
- <td colspan="4"><?php GetEditor("content",$myrow['content'],"400","Default","print","false");?></td>
- </tr>
- <tr>
- <td align="center" colspan="4">
- <button type="submit" class="btn btn-success btn-sm">保存</button>
- <a href="catalog_main.php" class="btn btn-outline-success btn-sm">返回</a>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </form>
- </div>
- </div>
- </div>
- <div id="mdlViewAPI" class="modal fade" tabindex="-1" aria-hidden="true">
- <div class="modal-dialog modal-xl">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title">跨站调用</h5>
- <button type="button" class="update-close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
- </div>
- <div class="modal-body">
- <form>
- <div class="form-group">
- <span>跨站调用功能用于同后台管理或其他网站之间调用栏目文档数据</span>
- </div>
- <div class="form-group">
- <label for="iptAPICode" class="mb-3">代码示例</label>
- <div class="nav nav-pills mb-3" id="data-tab" role="tablist">
- <button type="button" class="nav-link active" id="php-tab" data-toggle="tab" data-target="#nav-php" role="tab" aria-controls="nav-php" aria-selected="true">PHP</button>
- <button type="button" class="nav-link" id="js-tab" data-toggle="tab" data-target="#nav-js" role="tab" aria-controls="nav-js" aria-selected="true">Javasctipt</button>
- <button type="button" class="nav-link" id="go-tab" data-toggle="tab" data-target="#nav-go" role="tab" aria-controls="nav-go" aria-selected="false">Go</button>
- <button type="button" class="nav-link" id="python-tab" data-toggle="tab" data-target="#nav-python" role="tab" aria-controls="nav-python" aria-selected="false">Python3</button>
- </div>
- <div class="tab-content" id="data-tabContent">
- <div class="tab-pane fade show active" id="nav-php" role="tabpanel" aria-labelledby="php-tab">
- <pre><code id="codephp"></code></pre></div>
- <div class="tab-pane fade" id="nav-js" role="tabpanel" aria-labelledby="js-tab">
- <pre><code id="codejs"></code></pre>
- </div>
- <div class="tab-pane fade" id="nav-go" role="tabpanel" aria-labelledby="go-tab">
- <pre><code id="codego"></code></pre>
- </div>
- <div class="tab-pane fade" id="nav-python" role="tabpanel" aria-labelledby="python-tab">
- <pre><code id="codepython"></code></pre>
- </div>
- </div>
- </div>
- <div class="form-group">
- <label for="iptAPITag" class="mb-3">标签示例</label>
- <pre><code id="codetag"></code></pre>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <div class="btnStep"><button id="btnGoStep4" type="button" class="btn btn-success btn-sm" data-dismiss="modal">关闭</button></div>
- </div>
- </div>
- </div>
- </div>
- <div id="mdlAI" class="modal fade" tabindex="-1" aria-hidden="true">
- <div class="modal-dialog modal-xl">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title">小德AI助手:修改栏目</h5>
- <button type="button" class="update-close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
- </div>
- <div class="modal-body">
- <form>
- <div class="form-group">
- <textarea id="prompt" class="form-control" style="height:160px" placeholder="请输入修改栏目要求,例如:我需要栏目信息内容更丰富一些"></textarea>
- </div>
- <div class="form-group">
- <label for="modelid" class="form-label">选择模型</label>
- <?php
- $dsql->SetQuery("SELECT AM.*,A.title as aititle FROM `#@__ai_model` AM LEFT JOIN `#@__ai` A ON A.id = AM.aiid ORDER BY AM.sortrank ASC,AM.id DESC");
- $dsql->Execute();
- while ($row = $dsql->GetObject()) {
- ?>
- <option value="<?php echo $row->id;?>" <?php echo $row->isdefault==1?' selected' : '';?>><?php echo $row->model;?> <?php echo $row->aititle;?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <button id="btnAIAction" class="btn btn-success btn-sm">确定</button>
- </div>
- </div>
- </div>
- </div>
- <script>
- var channelArray = new Array();
- <?php
- $i = 0;
- foreach($channelArray as $k=> $arr)
- {
- echo "channelArray[$k] = \"{$arr['nid']}\";";
- }
- ?>
- function Nav() {
- if (window.navigator.userAgent.indexOf("MSIE") >= 1) return 'IE';
- else if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
- else return "OT";
- }
- function SelectTemplets(fname) {
- var pos = GetWinPos(800,600);
- window.open("./dialog/select_templets.php?f=" + fname, "poptempWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
- }
- function ShowHide(objname) {
- var obj = document.getElementById(objname);
- if (obj.style.display != "none")
- obj.style.display = "none";
- else {
- if (Nav() == 'IE') obj.style.display = "block";
- else obj.style.display = "block";
- }
- }
- function ShowObj(objname) {
- var obj = document.getElementById(objname);
- if (Nav() == 'IE') obj.style.display = "block";
- else obj.style.display = "block";
- }
- function HideObj(objname) {
- var obj = document.getElementById(objname);
- obj.style.display = "none";
- }
- function CheckTypeDir() {
- var upinyin = document.getElementById('upinyin');
- var tpobj = document.getElementById('typedir');
- if (upinyin.checked) tpobj.style.display = "none";
- else tpobj.style.display = "inline-block";
- }
- function ParTemplet(obj) {
- var sevvalue = channelArray[obj.value];
- var tobj = document.getElementById('smclass');
- var tempindex = document.getElementsByName('tempindex');
- var templist = document.getElementsByName('templist');
- var temparticle = document.getElementsByName('temparticle');
- var dfstyle = document.getElementsByName('dfstyle');
- var dfstyleValue = dfstyle[0].value;
- tempindex[0].value = dfstyleValue + "/index_" + sevvalue + ".htm";
- templist[0].value = dfstyleValue + "/list_" + sevvalue + ".htm";
- temparticle[0].value = dfstyleValue + "/article_" + sevvalue + ".htm";
- if (obj.value < 0) {
- if (Nav() == 'IE') tobj.style.display = "block";
- else tobj.style.display = "block";
- } else {
- tobj.style.display = "none";
- }
- }
- function CheckCross() {
- var cross2 = document.getElementById('cross2');
- var crossid = document.getElementById('crossid');
- if (cross2.checked) crossid.style.display = 'block';
- else crossid.style.display = 'none';
- }
- function makeAPIKey(){
- var apikey = document.getElementById('apikey');
- jQuery.get("sys_info.php?dopost=make_encode", function(data) {
- jQuery("#apikey").val(data);
- });
- }
- function showAPI(tid) {
- fetch('catalog_do.php?dopost=viewAPI&typeid=' + tid).then(resp => resp.text()).then((d) => {
- let data = JSON.parse(d);
- if (data.code == 0) {
- $("#codephp").html(data.data.phpcode);
- $("#codego").html(data.data.gocode);
- $("#codepython").html(data.data.pythoncode);
- $("#codejs").html(data.data.jscode);
- $("#codetag").html(data.data.tagcode);
- $("#mdlViewAPI").modal('show');
- }
- });
- }
- function showAI() {
- $("#mdlAI").modal('show');
- }
- let bodyHtml = "";
- $("#btnAIAction").click(async function() {
- let prompt = document.getElementById("prompt").value;
- let modelid = document.getElementById("modelid").value;
- let req = await fetch(`api.php?action=get_ai_server&pname=catalog_edit&tid=<?php echo $id?>&modelid=${modelid}&prompt=${prompt}`);
- let resp = await req.json();
- if (resp.code !== 0) {
- ShowMsg("获取服务器地址失败");
- return
- }
- let eventSource = new EventSource(resp.data);
- //新增状态跟踪变量
- let currentKey = null;
- let tagBuffer = "";
- let isClosingTag = false;
- $("#mdlAI").modal('hide');
- $("#btnAI").attr("disabled", "disabled");
- prompt = "";
- let lastChar = "";
- eventSource.onmessage = (event) => {
- const chars = event.data.split('');
- chars.forEach(char => {
- if (lastChar === '\\' && char === 'r') {
- char = '<br>'; //替换为br标签
- lastChar = ""; //清空追踪字符
- } else {
- lastChar = char; //记录当前字符
- }
- if (char === '\\') {
- return; //如果是反斜杠,跳过处理
- }
- if (currentKey) {
- if (char === '{') {
- isClosingTag = true;
- tagBuffer = '{';
- return;
- }
- if (isClosingTag) {
- tagBuffer += char;
- if (tagBuffer === `{/${currentKey}}`) {
- if (currentKey == "content") {
- CKEDITOR.instances["content"].setReadOnly(false);
- bodyHtml = "";
- } else {
- const input = document.querySelector(`[name="${currentKey}"]`);
- if (input) $(input).prop("disabled", false).removeClass("disabled"); //恢复输入状态
- }
- currentKey = null;
- isClosingTag = false;
- tagBuffer = "";
- return;
- }
- if (!`{/${currentKey}}`.startsWith(tagBuffer)) {
- if (currentKey == "content") {
- bodyHtml += tagBuffer;
- console.log(bodyHtml);
- CKEDITOR.instances["content"].setData(bodyHtml)
- } else {
- const input = document.querySelector(`[name="${currentKey}"]`);
- if (input) input.value += tagBuffer;
- }
-
- isClosingTag = false;
- tagBuffer = "";
- }
- } else {
- if (currentKey == "content") {
- bodyHtml += char;
- CKEDITOR.instances["content"].setData(bodyHtml)
- } else {
- const input = document.querySelector(`[name="${currentKey}"]`);
- if (input) {
- input.value += char;
- input.scrollTop = input.scrollHeight; //滚动到底部
- }
- }
-
- }
- } else {
- if (char === '{') {
- tagBuffer = '{';
- } else if (tagBuffer.startsWith('{')) {
- tagBuffer += char;
- if (char === '}') {
- const match = tagBuffer.match(/{([^>]+)}/);
- if (match) {
- currentKey = match[1];
- if (currentKey == "content") {
- CKEDITOR.instances["content"].setReadOnly(true);
- } else {
- const input = document.querySelector(`[name="${currentKey}"]`);
- if (input) {
- $(input).prop("disabled", true).addClass("disabled"); //仅禁用当前输入框
- input.value = "";
- }
- }
- }
- tagBuffer = "";
- }
- }
- }
- });
- };
- eventSource.onerror = (error) => {
- if (error.target.readyState === EventSource.CONNECTING) {
- ShowMsg("连接失败,请确保您已开启并正确配置了DedeBIZ小德AI助手。 <a class='text-success' href='https://www.dedebiz.com/ai?from=dedebiz' target='_blank'>如何配置?</a>");
- } else if (typeof error.data!=="undefined" && error.data !== "" && error.target.readyState !== EventSource.CLOSED) {
- ShowMsg(error.data);
- }
- $("#btnAI").prop("disabled", false);
- eventSource.close();
- };
- //监听特定事件close
- eventSource.addEventListener('close', (event) => {
- console.log('SSE connection closed:', event.data);
- $("#btnAI").prop("disabled", false);
- eventSource.close(); //关闭连接
- });
- });
- </script>
- </body>
- </html>
|