{$layout}

	{$template "node_menu"}

	<table class="ui table definition selectable">
		<tr>
			<td class="title">节点名称</td>
			<td>{{node.name}}</td>
		</tr>
		<tr>
			<td>启用状态</td>
			<td><label-on :v-is-on="node.isOn"></label-on></td>
		</tr>
        <tr>
            <td>所属集群</td>
            <td>
                <node-clusters-labels :v-primary-cluster="node.cluster" :v-secondary-clusters="node.secondaryClusters"></node-clusters-labels>
            </td>
        </tr>
        <tr v-show="node.isBackupForCluster || node.isBackupForGroup">
            <td>备用节点</td>
            <td>
                <span class="ui label basic small" v-if="node.isBackupForCluster">集群备用节点</span>
                <span class="ui label basic small" v-if="node.isBackupForGroup">分组备用节点</span>
                &nbsp; <a :href="'/clusters/cluster/node/settings/schedule?clusterId=' + clusterId + '&nodeId=' + node.id" style="font-size: 0.8em">[修改]</a>
            </td>
        </tr>
        <tr v-show="node.offlineDay.length > 0">
            <td>租期结束日期</td>
            <td>
                {{node.offlineDay.substring(0, 4)}}-{{node.offlineDay.substring(4, 6)}}-{{node.offlineDay.substring(6, 8)}} &nbsp; <a :href="'/clusters/cluster/node/settings/schedule?clusterId=' + clusterId + '&nodeId=' + node.id" style="font-size: 0.8em">[修改]</a>
                <p class="comment" v-if="node.isOffline"><span class="red">已到期</span></p>
            </td>
        </tr>
		<tr>
			<td>IP地址</td>
			<td>
				<div v-if="node.ipAddresses.length > 0">
					<div>
						<div v-for="(address, index) in node.ipAddresses" class="ui label small basic">
                            <span v-if="address.ip.indexOf(':') > -1" class="grey">[IPv6]</span> {{address.ip}}
                            <span class="small red" v-if="address.originIP != null && address.originIP.length > 0 && address.originIP != address.ip">（原：{{address.originIP}}）</span>
							<span class="small grey" v-if="address.name.length > 0">（备注：{{address.name}}<span v-if="!address.canAccess">，不公开访问</span>）</span>
							<span class="small grey" v-if="address.name.length == 0 && !address.canAccess">（不公开访问）</span>
                            <span class="small red" v-if="!address.isOn">[off]</span>
                            <span class="small red" v-if="!address.isUp">[down]</span>
                            <span class="small" v-if="address.thresholds != null && address.thresholds.length > 0">[阈值]</span>

                            <span v-if="address.clusters.length > 0">
                                &nbsp; <span class="small grey">专属集群：[</span><span v-for="(cluster, index) in address.clusters" class="small grey">{{cluster.name}}<span v-if="index < address.clusters.length - 1">，</span></span><span class="small grey">]</span>
                            </span>
						</div>
					</div>
				</div>
				<div v-else>
					<span class="disabled">暂时还没有填写IP地址。</span>
				</div>
			</td>
		</tr>
		<tr v-if="node.routes.length > 0">
			<td>DNS线路</td>
			<td>
                <span class="ui label tiny basic" v-for="route in node.routes">{{route.name}} <span class="grey small">（{{route.domainName}}）</span></span>
			</td>
		</tr>
        <tr v-if="node.records.length > 0">
            <td>DNS记录</td>
            <td>
                <div :style="{opacity: dnsIsExcludingLnNode ? 0.5 : 1.0}">
                    <table class="ui table celled">
                       <thead class="full-width">
                           <tr>
                               <th>集群</th>
                               <th>记录名</th>
                               <th>记录类型</th>
                               <th>线路</th>
                               <th>记录值</th>
                               <th>状态</th>
                           </tr>
                       </thead>

                        <tr v-for="record in node.records">
                            <td>{{record.clusterName}}</td>
                            <td>{{record.name}}</td>
                            <td>{{record.type}}</td>
                            <td>
                                <span v-if="record.route.length > 0">{{record.route}}</span>
                                <span v-else class="disabled">默认</span>
                            </td>
                            <td>{{record.value}}</td>
                            <td>
                                <span v-if="record.isBackup" class="red">备用节点</span>
                                <span v-else-if="record.isOffline" class="red">已下线</span>
                                <span v-else>正常</span>
                            </td>
                        </tr>
                    </table>
                    <p class="comment" v-if="!dnsIsExcludingLnNode">通过设置A记录可以将集群上的服务请求转发到不同线路的节点上。</p>
                </div>
                <p class="comment" v-if="dnsIsExcludingLnNode"><span class="red">当前集群DNS已设置不解析Ln节点，所以当前节点不会加入DNS解析；如需加入，请修改"集群设置" -- "DNS设置" -- "更多选项" -- "包含Ln节点"。</span></p>
                <p class="comment" v-if="!node.isInstalled"><span class="red">当前节点尚未完成安装，DNS解析记录将不会生效，<a :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id">[点此安装]</a>。</span></p>
            </td>
        </tr>
        <tr>
            <td>所属区域</td>
            <td>
                <span v-if="node.region != null" class="ui label small basic">{{node.region.name}}</span>
                <span v-else class="disabled">没有设置区域。</span>
            </td>
        </tr>
		<tr>
			<td>所属分组</td>
			<td>
				<span v-if="node.group != null" class="ui label small basic">{{node.group.name}}</span>
				<span v-else class="disabled">没有设置分组。</span>
			</td>
		</tr>
        <tr v-if="teaIsPlus">
            <td>级别</td>
            <td>
                <span :class="{blue: node.levelInfo.code > 1}">{{node.levelInfo.name}}</span>
                &nbsp; &nbsp; <span v-if="node.level > 1 && node.lnAddrs != null && node.lnAddrs.length > 0">
                    <span v-for="lnAddr in node.lnAddrs" class="ui label tiny basic">{{lnAddr}}</span>
                </span>
                <p class="comment" v-if="node.level > 1 && node.lnAddrs != null && node.lnAddrs.length > 0">指定了Ln节点访问地址。</p>
            </td>
        </tr>
		<tr>
			<td colspan="2"><more-options-indicator>更多选项</more-options-indicator></td>
		</tr>
		<tbody v-show="moreOptionsVisible">
            <tr>
                <td>同步IP名单</td>
                <td>
                    <span v-if="node.enableIPLists" class="green">Y</span>
                    <span v-else class="disabled">N</span>
                </td>
            </tr>
			<tr>
				<td>SSH主机地址</td>
				<td>
					<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
						<span v-if="node.login.params.host.length > 0">{{node.login.params.host}}</span>
						<span v-else class="disabled">尚未设置</span>
					</div>
					<div v-else class="disabled">
						尚未设置
					</div>
				</td>
			</tr>
			<tr>
				<td>SSH主机端口</td>
				<td>
					<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
						<span v-if="node.login.params.port > 0">{{node.login.params.port}}</span>
						<span v-else class="disabled">尚未设置</span>
					</div>
					<span v-else class="disabled">
						尚未设置
					</span>
				</td>
			</tr>
			<tr>
				<td>SSH登录认证</td>
				<td>
					<div v-if="node.login != null && node.login.grant != null && node.login.grant.id > 0">
						<a :href="'/clusters/grants/grant?grantId=' + node.login.grant.id">{{node.login.grant.name}}<span class="small grey">（{{node.login.grant.methodName}}）</span><span class="small grey" v-if="node.login.grant.username.length > 0">（{{node.login.grant.username}}）</span></a>
					</div>
					<span v-else class="disabled">
						尚未设置
					</span>
				</td>
			</tr>
            <tr>
                <td>缓存硬盘容量</td>
                <td>
                    <span v-if="node.maxCacheDiskCapacity == null || node.maxCacheDiskCapacity.count <= 0" class="disabled">没有限制</span>
                   <div v-else>
                       <size-capacity-view :v-value="node.maxCacheDiskCapacity"></size-capacity-view>
                   </div>
                </td>
            </tr>
            <tr>
                <td>硬盘预估写入最大速度</td>
                <td>
                    <span v-if="node.status.diskWritingSpeedMB == 0">-</span><span v-if="node.status.diskWritingSpeedMB > 0">&gt; {{node.status.diskWritingSpeedMB}}</span>
                    <span v-if="node.status.diskWritingSpeedMB > 1000">MiB/s 极快</span>
                    <span v-else-if="node.status.diskWritingSpeedMB > 150">MiB/s 快</span>
                    <span v-else-if="node.status.diskWritingSpeedMB > 0">MiB/s 一般</span>
                </td>
            </tr>
            <tr>
                <td>缓存内存容量</td>
                <td>
                    <span v-if="node.maxCacheMemoryCapacity == null || node.maxCacheMemoryCapacity.count <= 0" class="disabled">没有限制</span>
                    <div v-else>
                        <size-capacity-view :v-value="node.maxCacheMemoryCapacity"></size-capacity-view>
                    </div>
                </td>
            </tr>
            <tr>
                <td>CPU线程数</td>
                <td>
                    <span v-if="node.maxCPU > 0">{{node.maxCPU}}线程</span>
                    <span v-else class="disabled">没有限制。</span>
                </td>
            </tr>
            <tr>
                <td>API节点地址</td>
                <td>
                    <div v-if="node.apiNodeAddrs != null && node.apiNodeAddrs.length > 0">
                        <span v-for="addr in node.apiNodeAddrs" class="ui label basic small">{{addr}}</span>
                    </div>
                    <span v-else class="disabled">使用全局设置</span>
                </td>
            </tr>
		</tbody>
	</table>
	<div class="ui divider"></div>

	<h3>运行状态</h3>
	<table class="ui table definition selectable">
		<tr>
			<td class="title">运行状态</td>
			<td>
				<div  v-if="node.status.isActive">
					<span class="green">运行中</span> &nbsp;
					<a href="" @click.prevent="stopNode()" v-if="!isStopping"><span>[通过SSH停止]</span></a>
					<span v-if="isStopping">[停止中...]</span>
				</div>
				<div v-else>
					<span class="red">已断开</span> &nbsp;
					<a href="" @click.prevent="startNode()" v-if="node.isInstalled && !isStarting"><span>[通过SSH启动]</span></a>
					<span v-if="node.isInstalled && isStarting">[启动中...]</span>
					<a v-if="!node.isInstalled" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" ><span>去安装&gt;</span></a>
				</div>
			</td>
		</tr>

		<tbody v-show="node.status.isActive">
			<tr>
				<td>CPU用量</td>
				<td>{{node.status.cpuUsageText}} &nbsp; <span v-if="node.status.cpuPhysicalCount > 0" class="small grey">（{{node.status.cpuPhysicalCount}}核心/{{node.status.cpuLogicalCount}}线程）</span></td>
			</tr>
			<tr>
				<td>内存用量</td>
				<td>{{node.status.memUsageText}}</td>
			</tr>
			<tr>
				<td>连接数</td>
				<td>{{node.status.connectionCount}}</td>
			</tr>
            <tr>
                <td>负载</td>
                <td>{{node.status.load1m}} &nbsp; {{node.status.load5m}} &nbsp; {{node.status.load15m}} &nbsp; <tip-icon content="三个数字分别代表1分钟、5分钟、15分钟平均负载"></tip-icon></td>
            </tr>
            <tr>
                <td>缓存用量</td>
                <td>
                    硬盘：{{node.status.cacheTotalDiskSize}}  &nbsp; 内存：{{node.status.cacheTotalMemorySize}}
                </td>
            </tr>
        </tbody>
        <tbody>
            <tr v-if="node.status.buildVersion != null && node.status.buildVersion.length > 0">
                <td>版本</td>
                <td>v{{node.status.buildVersion}}
                    &nbsp; <a :href="'/clusters/cluster/upgradeRemote?clusterId=' + clusterId" v-if="shouldUpgrade"><span class="red">发现新版本v{{newVersion}} &raquo;</span></a>
                </td>
            </tr>
            <tr v-if="node.status.exePath != null && node.status.exePath.length > 0">
                <td>主程序位置</td>
                <td>{{node.status.exePath}}</td>
            </tr>
            <tr>
                <td>最近API连接状况</td>
                <td>
                    <span v-if="node.status.apiSuccessPercent > 0 && node.status.apiAvgCostSeconds > 0">
                        <span v-if="node.status.apiSuccessPercent <= 50" class="red">连接错误异常严重（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                        <span v-else-if="node.status.apiSuccessPercent <= 80" class="red">连接错误较多（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                        <span v-else-if="node.status.apiSuccessPercent < 100" class="orange">有连接错误发生（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                        <span v-else>
                            <span v-if="node.status.apiAvgCostSeconds <= 1" class="green">连接良好</span>
                            <span v-else-if="node.status.apiAvgCostSeconds <= 5" class="orange">连接基本稳定（平均{{round(node.status.apiAvgCostSeconds)}}秒）</span>
                            <span v-else-if="node.status.apiAvgCostSeconds <= 10" class="orange">连接速度较慢（平均{{round(node.status.apiAvgCostSeconds)}}秒）</span>
                            <span v-else class="red">连接非常慢（平均{{round(node.status.apiAvgCostSeconds)}}秒），请改善当前节点和API节点之间通讯</span>
                        </span>
                    </span>
                    <span v-else class="disabled">尚未上报数据</span>
                </td>
            </tr>
            <tr v-if="nodeDatetime.length > 0">
                <td>上次更新时间</td>
                <td>
                    {{nodeDatetime}}
                    <p class="comment" v-if="nodeTimeDiff > 30"><span class="red">当前节点时间与API节点时间相差 {{nodeTimeDiff}} 秒，请同步节点时间。</span></p>
                </td>
            </tr>
		</tbody>
	</table>
	<p class="comment" v-if="node.status.isActive">每隔30秒钟更新一次运行状态。</p>

	<div class="ui divider"></div>
	<h3>安装信息</h3>
	<table class="ui table definition selectable">
		<tr>
			<td>节点ID<em>（id）</em></td>
			<td>{{node.uniqueId}}</td>
		</tr>
		<tr>
			<td>密钥<em>（secret）</em></td>
			<td>{{node.secret}}</td>
		</tr>
		<tr>
			<td class="title">安装目录</td>
			<td>
				<div v-if="node.installDir.length == 0">使用集群设置<span v-if="node.cluster != null && node.cluster.installDir.length > 0">（{{node.cluster.installDir}}）</span></div>
				<span v-else>{{node.installDir}}</span>
			</td>
		</tr>
		<tr>
			<td>已安装</td>
			<td>
				<span v-if="node.isInstalled" class="green">已安装 &nbsp; <a href="" @click.prevent="showMoreOps"><span class="small">[操作]</span></a></span>
				<a v-else :href="'/clusters/cluster/installNode?clusterId=' + clusterId + '&nodeId=' + nodeId" class="underline" title="点击进入安装界面"><span class="red">未安装</span></a>
			</td>
		</tr>
        <tr v-show="moreOpsVisible && node.isInstalled">
            <td>操作</td>
            <td><a href="" @click.prevent="uninstallNode">[卸载]</a> </td>
        </tr>
	</table>