Redis节点管理独立
大石头 authored at 2021-03-18 09:00:21
2.11 KiB
Stardust
@using NewLife;
@using NewLife.Web;
@using XCode;
@using System.Linq;
@using Stardust.Data.Nodes;
@{
    var id = (Object)Model + "";
    var page = ViewBag.Page as Pager;

    if (id.IsNullOrEmpty()) { id = "redisId"; }
    var redisId = page[id];
    var showValue = RedisNode.FindById(redisId.ToInt())?.Name;

    var set = NewLife.Cube.Setting.Current;
    var res = set.ResourceUrl;
    if (String.IsNullOrEmpty(res)) res = "/Content";
    res = res.TrimEnd('/');
}

<div class="form-group" style="position:relative">
    <div class="col-lg-12">
        <div class="input-group">
            <input type="hidden" name="@id" id="@id" value="@redisId" />
            <input type="text" class="form-control" id="@(id)_select" placeholder="搜索Redis" value="@showValue">
            <div class="input-group-btn">
                <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
            </div>
        </div>
    </div>
</div>

<script src="@res/bootstrap-suggest.js"></script>
<script type="text/javascript">
    $(function () {
        $("#@(id)_select").bsSuggest({
            url: "/Nodes/RedisNode/NodeSearch?key=",
            getDataMethod:"url",
            effectiveFieldsAlias: { ID: "编号", Name: "名称", Server: "地址", Category: "类别" },
            ignorecase: true,
            showHeader: true,
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时,延迟到有输入/获取到焦点时才请求数据
            hideOnSelect: true,
            idField: "ID",
            showBtn: false,
            keyField: "Name",
            clearable: true,
            searchingTip: '搜索中...',
            allowNoKeyword: true,
            delay: 500,
            emptyTip: '无数据',
            containerValueId: '@id',
            fnProcessData: function (result) {
                dt = {};
                dt.value = result.data;
                return dt;
            }
        }).on('onSetSelectValue', function (e, keyword, data) {
            $('#@id').val(keyword.id);
        }).on('onUnsetSelectValue', function () {
            $('#@id').val('');
        });
    });
</script>