mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	使用CodeMirror高亮各处的配置信息
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
Vue.component("download-link", {
 | 
			
		||||
	props: ["v-element", "v-file"],
 | 
			
		||||
	props: ["v-element", "v-file", "v-value"],
 | 
			
		||||
	created: function () {
 | 
			
		||||
		let that = this
 | 
			
		||||
		setTimeout(function () {
 | 
			
		||||
@@ -18,15 +18,20 @@ Vue.component("download-link", {
 | 
			
		||||
	},
 | 
			
		||||
	methods: {
 | 
			
		||||
		composeURL: function () {
 | 
			
		||||
			let text = ""
 | 
			
		||||
			if (this.vValue != null) {
 | 
			
		||||
				text = this.vValue
 | 
			
		||||
			} else {
 | 
			
		||||
				let e = document.getElementById(this.vElement)
 | 
			
		||||
				if (e == null) {
 | 
			
		||||
					teaweb.warn("找不到要下载的内容")
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
			let text = e.innerText
 | 
			
		||||
				text = e.innerText
 | 
			
		||||
				if (text == null) {
 | 
			
		||||
					text = e.textContent
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return Tea.url("/ui/download", {
 | 
			
		||||
				file: this.file,
 | 
			
		||||
				text: text
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								web/public/js/components/common/source-code-box.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								web/public/js/components/common/source-code-box.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
let sourceCodeBoxIndex = 0
 | 
			
		||||
 | 
			
		||||
Vue.component("source-code-box", {
 | 
			
		||||
	props: ["type", "id"],
 | 
			
		||||
	mounted: function () {
 | 
			
		||||
		let box = document.getElementById("source-code-box-" + this.index)
 | 
			
		||||
		let valueBox = document.getElementById(this.valueBoxId)
 | 
			
		||||
		let value = ""
 | 
			
		||||
		if (valueBox.textContent != null) {
 | 
			
		||||
			value = valueBox.textContent
 | 
			
		||||
		} else if (valueBox.innerText != null) {
 | 
			
		||||
			value = valueBox.innerText
 | 
			
		||||
		}
 | 
			
		||||
		let boxEditor = CodeMirror.fromTextArea(box, {
 | 
			
		||||
			theme: "idea",
 | 
			
		||||
			lineNumbers: true,
 | 
			
		||||
			value: "",
 | 
			
		||||
			readOnly: true,
 | 
			
		||||
			showCursorWhenSelecting: true,
 | 
			
		||||
			height: "auto",
 | 
			
		||||
			//scrollbarStyle: null,
 | 
			
		||||
			viewportMargin: Infinity,
 | 
			
		||||
			lineWrapping: true,
 | 
			
		||||
			highlightFormatting: false,
 | 
			
		||||
			indentUnit: 4,
 | 
			
		||||
			indentWithTabs: true
 | 
			
		||||
		})
 | 
			
		||||
		boxEditor.setValue(value)
 | 
			
		||||
 | 
			
		||||
		let info = CodeMirror.findModeByMIME(this.type)
 | 
			
		||||
		if (info != null) {
 | 
			
		||||
			boxEditor.setOption("mode", info.mode)
 | 
			
		||||
			CodeMirror.modeURL = "/codemirror/mode/%N/%N.js"
 | 
			
		||||
			CodeMirror.autoLoadMode(boxEditor, info.mode)
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	data: function () {
 | 
			
		||||
		let index = sourceCodeBoxIndex++
 | 
			
		||||
 | 
			
		||||
		let valueBoxId = 'source-code-box-value-' + sourceCodeBoxIndex
 | 
			
		||||
		if (this.id != null) {
 | 
			
		||||
			valueBoxId = this.id
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return {
 | 
			
		||||
			index: index,
 | 
			
		||||
			valueBoxId: valueBoxId
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	template: `<div class="source-code-box">
 | 
			
		||||
	<div style="display: none" :id="valueBoxId"><slot></slot></div>
 | 
			
		||||
	<textarea :id="'source-code-box-' + index"></textarea>
 | 
			
		||||
</div>`
 | 
			
		||||
})
 | 
			
		||||
@@ -643,4 +643,15 @@ td .label.small {
 | 
			
		||||
td {
 | 
			
		||||
  word-break: break-all;
 | 
			
		||||
}
 | 
			
		||||
.source-code-box .CodeMirror {
 | 
			
		||||
  border: 1px solid #eee;
 | 
			
		||||
  height: auto !important;
 | 
			
		||||
}
 | 
			
		||||
.source-code-box .CodeMirror-vscrollbar {
 | 
			
		||||
  width: 6px;
 | 
			
		||||
  border-radius: 3px !important;
 | 
			
		||||
}
 | 
			
		||||
.source-code-box .CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
 | 
			
		||||
  border-radius: 2px;
 | 
			
		||||
}
 | 
			
		||||
/*# sourceMappingURL=@layout.css.map */
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -706,3 +706,20 @@ td .label.small {
 | 
			
		||||
td {
 | 
			
		||||
	word-break: break-all;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// codemirror
 | 
			
		||||
.source-code-box {
 | 
			
		||||
	.CodeMirror {
 | 
			
		||||
		border: 1px solid #eee;
 | 
			
		||||
		height: auto !important;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	.CodeMirror-vscrollbar {
 | 
			
		||||
		width: 6px;
 | 
			
		||||
		border-radius: 3px !important;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	.CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
 | 
			
		||||
		border-radius: 2px;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<h3>安装步骤</h3>
 | 
			
		||||
<ol class="ui list">
 | 
			
		||||
@@ -15,8 +16,8 @@
 | 
			
		||||
	<tr>
 | 
			
		||||
		<td class="title">configs/api.yaml<em><br/><download-link :v-element="'api-code'" :v-file="'api.yaml'">[下载]</download-link></em></td>
 | 
			
		||||
		<td>
 | 
			
		||||
			<pre id="api-code">nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</pre>
 | 
			
		||||
			<source-code-box id="api-code" type="text/yaml">nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</source-code-box>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>
 | 
			
		||||
	<tr>
 | 
			
		||||
@@ -27,7 +28,7 @@ secret: "{{node.secret}}"</pre>
 | 
			
		||||
				<span v-else class="red">无法生成配置内容,错误原因:</span>
 | 
			
		||||
				{{dbConfig.error}}
 | 
			
		||||
			</span>
 | 
			
		||||
			<pre v-show="dbConfig.config.length > 0" id="db-code">{{dbConfig.config}}</pre>
 | 
			
		||||
            <source-code-box id="db-code" type="text/yaml">{{dbConfig.config}}</source-code-box>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>
 | 
			
		||||
</table>
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
{$template "/left_menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<div class="right-box">
 | 
			
		||||
	<p>在官网下载节点安装包,然后通过修改节点安装包中的<code-label>configs/cluster.yaml</code-label>,启动后会自动注册节点。</p>
 | 
			
		||||
@@ -10,10 +11,10 @@
 | 
			
		||||
				<em><download-link :v-element="'cluster-config-box'" :v-file="'cluster.yaml'">[下载]</download-link></em>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<pre id="cluster-config-box">rpc:
 | 
			
		||||
				<source-code-box id="cluster-config-box" type="text/yaml">rpc:
 | 
			
		||||
	endpoints: [ {{cluster.endpoints}} ]
 | 
			
		||||
clusterId: "{{cluster.uniqueId}}"
 | 
			
		||||
	secret: "{{cluster.secret}}"</pre>
 | 
			
		||||
secret: "{{cluster.secret}}"</source-code-box>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
	</table>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
 | 
			
		||||
{$template "node_menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<!-- 已安装 -->
 | 
			
		||||
<div v-if="node.isInstalled">
 | 
			
		||||
@@ -33,10 +33,10 @@
 | 
			
		||||
            <td>配置文件<em>(configs/api.yaml)</em><br/>
 | 
			
		||||
            <em><download-link :v-element="'rpc-code'" :v-file="'api.yaml'">[下载]</download-link ></em></td>
 | 
			
		||||
            <td>
 | 
			
		||||
					<pre id="rpc-code">rpc:
 | 
			
		||||
					<source-code-box id="rpc-code" type="text/yaml">rpc:
 | 
			
		||||
  endpoints: [ {{apiEndpoints}} ]
 | 
			
		||||
nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</pre>
 | 
			
		||||
secret: "{{node.secret}}"</source-code-box>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<h3>安装步骤</h3>
 | 
			
		||||
<ol class="ui list">
 | 
			
		||||
@@ -14,10 +15,10 @@
 | 
			
		||||
	<tr>
 | 
			
		||||
		<td class="title">configs/api.yaml<em><br/><download-link :v-element="'api-code'" :v-file="'api.yaml'">[下载]</download-link></em></td>
 | 
			
		||||
		<td>
 | 
			
		||||
			<pre id="api-code">rpc:
 | 
			
		||||
			<source-code-box id="api-code" type="text/yaml">rpc:
 | 
			
		||||
  endpoints: [ {{apiEndpoints}} ]
 | 
			
		||||
nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</pre>
 | 
			
		||||
secret: "{{node.secret}}"</source-code-box>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>
 | 
			
		||||
</table>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<h3>安装步骤</h3>
 | 
			
		||||
<ol class="ui list">
 | 
			
		||||
@@ -14,10 +15,10 @@
 | 
			
		||||
	<tr>
 | 
			
		||||
		<td class="title">configs/api.yaml<em><br/><download-link :v-element="'api-code'" :v-file="'api.yaml'">[下载]</download-link></em></td>
 | 
			
		||||
		<td>
 | 
			
		||||
			<pre id="api-code">rpc:
 | 
			
		||||
			<source-code-box id="api-code" type="text/yaml">rpc:
 | 
			
		||||
  endpoints: [ {{apiEndpoints}} ]
 | 
			
		||||
nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</pre>
 | 
			
		||||
secret: "{{node.secret}}"</source-code-box>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>
 | 
			
		||||
</table>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
{$template "/code_editor"}
 | 
			
		||||
 | 
			
		||||
<h3>安装步骤</h3>
 | 
			
		||||
<ol class="ui list">
 | 
			
		||||
@@ -14,10 +15,10 @@
 | 
			
		||||
	<tr>
 | 
			
		||||
		<td class="title">configs/api.yaml<em><br/><download-link :v-element="'api-code'" :v-file="'api.yaml'">[下载]</download-link></em></td>
 | 
			
		||||
		<td>
 | 
			
		||||
			<pre id="api-code">rpc:
 | 
			
		||||
			<source-code-box id="api-code" type="text/yaml">rpc:
 | 
			
		||||
  endpoints: [ {{apiEndpoints}} ]
 | 
			
		||||
nodeId: "{{node.uniqueId}}"
 | 
			
		||||
secret: "{{node.secret}}"</pre>
 | 
			
		||||
secret: "{{node.secret}}"</source-code-box>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>
 | 
			
		||||
</table>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user