-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from ustclug/vue-term
Multiple enhancements to UI
- Loading branch information
Showing
4 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,15 @@ <h1>修改个人信息</h1> | |
如果你看到这条消息,说明你的浏览器版本过低或网络存在问题,导致比赛平台不能正常加载。请忽略以下显示的任何信息,换用最新版 Firefox 或 Chrome 浏览器访问比赛平台。 | ||
</div> | ||
<div v-if="user.group==='banned'" class="msg-error"> | ||
由于违反规则,你的参赛资格已被取消,如有疑问请联系 <a href="mailto:[email protected]">[email protected]</a>。 | ||
由于违反规则,你的参赛资格已被取消,如有疑问请联系 <a href="mailto:[email protected]">[email protected]</a>, | ||
并在邮件中粘贴下面的 token。 | ||
</div> | ||
<div v-if="user && user.group==='banned'" class="msg-info"> | ||
<label for="token">Token:</label> | ||
<button @click.prevent.stop="token_show=!token_show">{{ token_show?'隐藏':'显示' }}</button> | ||
<input v-show="token_show" type="text" id="token" :value="user.token" readonly> | ||
<button @click.prevent.stop="token_copy()">{{ token_copy_text }}</button> | ||
Token 是一些题目的登录凭证,禁止分享,否则视为作弊 | ||
</div> | ||
<div v-if="info.length" class="msg-info"> | ||
<div v-for="i in info">{{ i }}</div> | ||
|
@@ -89,6 +97,21 @@ <h1>修改个人信息</h1> | |
{{ user_.json|json_script:'json-user' }} | ||
{{ profile_required|json_script:'json-profile_required' }} | ||
<script> | ||
function token_copy() { | ||
let t = app.token_show; | ||
app.token_show = true; | ||
Vue.nextTick(function () { | ||
let copyText = document.getElementById("token"); | ||
copyText.select(); | ||
copyText.setSelectionRange(0, 99999); | ||
document.execCommand("copy"); | ||
app.token_show = t; | ||
app.token_copy_text = '已复制'; | ||
setTimeout(function () { | ||
app.token_copy_text = '复制'; | ||
}, 1000); | ||
}); | ||
} | ||
let user = JSON.parse(document.getElementById('json-user').textContent); | ||
let profile_required = JSON.parse(document.getElementById('json-profile_required').textContent); | ||
let fields_required = {}; | ||
|
@@ -132,6 +155,8 @@ <h1>修改个人信息</h1> | |
fields: fields_required, | ||
info, | ||
submit_disabled: false, | ||
token_show: false, | ||
token_copy_text: '复制', | ||
}, | ||
methods: { | ||
submit() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,96 @@ | ||
{% extends 'base.html' %} | ||
{% load static %} | ||
|
||
{% block js %} | ||
{{ block.super }} | ||
<script src="{% static 'vue.min.js' %}"></script> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% verbatim %} | ||
<div id="app"> | ||
<form method="post"> | ||
{% endverbatim %}{% comment %} 用户条款页面支持以下的扩展: | ||
<script id="json-quiz" type="application/json"> | ||
{"header": "请选择所有不违反以上条款的内容:", "questions": [[true, "使用搜索引擎搜索以尝试解题"], [false, "问做出题目的舍友 flag"], [false, "在群聊中分享自己的解题方法"], [true, "一边听歌一边做题"]]} | ||
</script> | ||
{% endcomment %} | ||
{% csrf_token %} | ||
{% for obj in terms %} | ||
<h1>{{ obj.name }}</h1> | ||
<input type="hidden" name="terms" value="{{ obj.pk }}"> | ||
<div>{{ obj.content|safe }}</div> | ||
{% endfor %} | ||
{% if user_ %} | ||
<button type="submit" class="pure-button pure-button-primary">我理解并同意以上条款</button> | ||
{% endif %} | ||
{% verbatim %} | ||
<div v-if="user_"> | ||
<div id="vue-quiz" v-if="quizs"> | ||
<hr> | ||
<p>以下问题回答正确后,同意按钮才会启用。</p> | ||
<span v-if="quizs.header">{{ quizs.header }}</span> | ||
<ul> | ||
<li v-for="(quiz, index) in quizs.questions"> | ||
<div> | ||
<input type="checkbox" :name="`quiz-${index}`" @change="check()"> | ||
<label v-for="`quiz-${quiz.pk}`">{{ quiz[1] }}</label> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
<!-- 请读者注意:以任何形式提交理解并同意的网络请求均视为已经完全理解并且同意以上条款的内容。 --> | ||
<button type="submit" class="pure-button pure-button-primary" :disabled="!enable_submit">我理解并同意以上条款</button> | ||
</div> | ||
</form> | ||
</div> | ||
{% endverbatim %} | ||
{{ user_.json|json_script:'json-user' }} | ||
<script> | ||
app = new Vue({ | ||
el: '#app', | ||
data: { | ||
user_: JSON.parse(document.getElementById('json-user').textContent), | ||
enable_submit: false, | ||
quizs: null, | ||
}, | ||
created() { | ||
this.init_quiz(); | ||
}, | ||
methods: { | ||
init_quiz() { | ||
const ele = document.getElementById('json-quiz'); | ||
if (!ele) { | ||
this.enable_submit = true; | ||
return; | ||
} | ||
const quizs = JSON.parse(ele.textContent); | ||
// comment out this if you don't want to shuffle the quizs. | ||
this.inplace_shuffle(quizs.questions); | ||
this.quizs = quizs; | ||
}, | ||
check() { | ||
for (const [index, quiz] of this.quizs.questions.entries()) { | ||
const ele = document.getElementsByName(`quiz-${index}`)[0]; | ||
const user_checked = ele.checked; | ||
const correct_ans = quiz[0]; | ||
if (correct_ans != user_checked) { | ||
this.enable_submit = false; | ||
return; | ||
} | ||
} | ||
this.enable_submit = true; | ||
}, | ||
inplace_shuffle(array) { | ||
// https://stackoverflow.com/a/2450976/8460426 | ||
let current_index = array.length; | ||
let random_index; | ||
|
||
while (current_index > 0) { | ||
random_index = Math.floor(Math.random() * current_index); | ||
current_index--; | ||
|
||
[array[current_index], array[random_index]] = [array[random_index], array[current_index]]; | ||
} | ||
} | ||
} | ||
}); | ||
</script> | ||
{% endblock %} |