|
|
@@ -1,28 +1,56 @@
|
|
|
<template>
|
|
|
- <div class="git-graph-body">
|
|
|
- <div class="command-container">
|
|
|
- <div class="command-box" ref="command-box">
|
|
|
- <b-field
|
|
|
- v-for="c in commandHistory"
|
|
|
- v-bind:key="c.id"
|
|
|
- :type="c.result"
|
|
|
- :message="c.info"
|
|
|
+ <div>
|
|
|
+ <div class="instruction">
|
|
|
+ <div class="line">
|
|
|
+ <b-tag>题目要求</b-tag>
|
|
|
+ <p>{{ instruction }}</p>
|
|
|
+ </div>
|
|
|
+ <div class="line">
|
|
|
+ <b-tag @click.native="handleShowHint">提示</b-tag>
|
|
|
+ <b-tag
|
|
|
+ v-show="showHint"
|
|
|
+ closable
|
|
|
+ aria-close-label="Close tag"
|
|
|
+ @close="showHint = false"
|
|
|
+ >{{ hint }}</b-tag
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ <div class="line">
|
|
|
+ <b-tag @click.native="handleShowAnswer">参考答案</b-tag>
|
|
|
+ <b-tag
|
|
|
+ v-show="showAnswer"
|
|
|
+ closable
|
|
|
+ aria-close-label="Close tag"
|
|
|
+ @close="showAnswer = false"
|
|
|
+ >{{ answer }}</b-tag
|
|
|
>
|
|
|
- <b-input v-model="c.value" size="is-small" readOnly></b-input>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="git-graph-body">
|
|
|
+ <div class="command-container">
|
|
|
+ <div class="command-box" ref="command-box">
|
|
|
+ <b-field
|
|
|
+ v-for="c in commandHistory"
|
|
|
+ v-bind:key="c.id"
|
|
|
+ :type="c.result"
|
|
|
+ :message="c.info"
|
|
|
+ >
|
|
|
+ <b-input v-model="c.value" size="is-small" readOnly></b-input>
|
|
|
+ </b-field>
|
|
|
+ </div>
|
|
|
+ <b-field>
|
|
|
+ <!-- keypress事件 屏蔽中文输入法的enter -->
|
|
|
+ <b-input
|
|
|
+ id="command-input"
|
|
|
+ placeholder="git"
|
|
|
+ v-model="commandInput"
|
|
|
+ @keypress.enter.native="handleCommand"
|
|
|
+ ></b-input>
|
|
|
</b-field>
|
|
|
</div>
|
|
|
- <b-field>
|
|
|
- <!-- keypress事件 屏蔽中文输入法的enter -->
|
|
|
- <b-input
|
|
|
- id="command-input"
|
|
|
- placeholder="git"
|
|
|
- v-model="commandInput"
|
|
|
- @keypress.enter.native="handleCommand"
|
|
|
- ></b-input>
|
|
|
- </b-field>
|
|
|
+ <!--分支图-->
|
|
|
+ <div class="gitgraph-container"><div id="gitgraph"></div></div>
|
|
|
</div>
|
|
|
- <!--分支图-->
|
|
|
- <div class="gitgraph-container"><div id="gitgraph"></div></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -31,7 +59,15 @@ import { createGitgraph, templateExtend, TemplateName } from "@gitgraph/js";
|
|
|
export default {
|
|
|
name: "GitGraph",
|
|
|
components: {},
|
|
|
- props: {},
|
|
|
+ props: {
|
|
|
+ name: String,
|
|
|
+ id: Number,
|
|
|
+ description: String,
|
|
|
+ instruction: String,
|
|
|
+ preCode: Array,
|
|
|
+ hint: String,
|
|
|
+ answer: String
|
|
|
+ },
|
|
|
watch: {},
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -39,15 +75,23 @@ export default {
|
|
|
commandHistory: [],
|
|
|
fastCommandPointer: 0, // 上下按键访问历史命令
|
|
|
branchList: [],
|
|
|
- currentBranchName: ""
|
|
|
+ currentBranchName: "",
|
|
|
+ showHint: false,
|
|
|
+ showAnswer: false
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
/** 解析命令相关方法 */
|
|
|
- handleCommand(event) {
|
|
|
+ handleCommand(event, isPreCode) {
|
|
|
//1 分词
|
|
|
- let command = event.target.value;
|
|
|
- command = command.trim();
|
|
|
+ let command;
|
|
|
+ if (!isPreCode) {
|
|
|
+ command = event.target.value;
|
|
|
+ command = command.trim();
|
|
|
+ } else {
|
|
|
+ command = event;
|
|
|
+ command = command.trim();
|
|
|
+ }
|
|
|
let array = command.split(" ");
|
|
|
array = array.filter(i => i.length > 0);
|
|
|
console.log("array:", array);
|
|
|
@@ -170,7 +214,9 @@ export default {
|
|
|
} else {
|
|
|
let newBranch = this.gitGraph.branch(branchName);
|
|
|
this.branchList.push(newBranch);
|
|
|
- this.currentBranchName = branchName;
|
|
|
+ if (selfUse) {
|
|
|
+ this.currentBranchName = branchName; // checkout -b
|
|
|
+ }
|
|
|
if (!selfUse) {
|
|
|
this.commandCorrect(command);
|
|
|
}
|
|
|
@@ -211,6 +257,13 @@ export default {
|
|
|
} else {
|
|
|
this.commandWrong(command, "no branch name" + branchName);
|
|
|
}
|
|
|
+ },
|
|
|
+ // 其他方法
|
|
|
+ handleShowHint() {
|
|
|
+ this.showHint = !this.showHint;
|
|
|
+ },
|
|
|
+ handleShowAnswer() {
|
|
|
+ this.showAnswer = !this.showAnswer;
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -230,6 +283,11 @@ export default {
|
|
|
template: myTemplate
|
|
|
});
|
|
|
|
|
|
+ // 执行preCode
|
|
|
+ for (let i = 0; i < this.preCode.length; i++) {
|
|
|
+ this.handleCommand(this.preCode[i], true);
|
|
|
+ }
|
|
|
+
|
|
|
// ⬆快捷键
|
|
|
document.onkeyup = function(e) {
|
|
|
if (e.key === "ArrowUp") {
|
|
|
@@ -255,6 +313,24 @@ export default {
|
|
|
justify-content: space-between;
|
|
|
padding: 10px 20px;
|
|
|
}
|
|
|
+
|
|
|
+.instruction {
|
|
|
+ padding-left: 10px;
|
|
|
+ .line {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin: 2px 0;
|
|
|
+ p {
|
|
|
+ font-size: $size-small;
|
|
|
+ color: $text;
|
|
|
+ margin-left: 12px;
|
|
|
+ }
|
|
|
+ span.tag {
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
.command-container {
|
|
|
width: 50%;
|
|
|
padding: 20px 20px 10px 20px;
|