新功能
This commit is contained in:
@@ -4,12 +4,15 @@
|
||||
:visible.sync="dialogVisible"
|
||||
width="50%"
|
||||
:before-close="handleClose">
|
||||
<p class="tip">{{$t('Notloggedinyet')}}</p>
|
||||
<el-form :model="dataForm" ref="dataForm" :rules="dataRule" :label-width="$i18n.locale === 'en-us' ? '' : '1.1rem'" size="mini">
|
||||
<el-form-item :label="$t('Administratorpassword')" prop="password">
|
||||
<el-input :placeholder="$t('Pleasepassword')" v-model="dataForm.password" show-password @focus="show" data-layout="normal"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<p class="tip" v-if="$store.getters.userInfo === 'true'">登录成功</p>
|
||||
<div v-else>
|
||||
<p class="tip">{{$t('Notloggedinyet')}}</p>
|
||||
<el-form :model="dataForm" ref="dataForm" :rules="dataRule" :label-width="$i18n.locale === 'en-us' ? '' : '1.1rem'" size="mini">
|
||||
<el-form-item :label="$t('Administratorpassword')" prop="password">
|
||||
<el-input :placeholder="$t('Pleasepassword')" v-model="dataForm.password" id="password" show-password @focus="show" data-layout="normal"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-row type="flex" justify="space-around" style="margin-top: .3rem">
|
||||
<el-col :span="7"><button class="button_control button_control_disabled" @click="exitUser"><p>{{ $t('Logout') }}</p></button></el-col>
|
||||
<el-col :span="7"><button class="button_control" @click="dataFormSubmit"><p>{{$t('Login')}}</p></button></el-col>
|
||||
@@ -19,6 +22,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
@@ -31,6 +35,7 @@ export default {
|
||||
{ required: true, message: this.$t('Passwordnotempty'), trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
passwords: [], // 存储文件中的密码
|
||||
visible: false,
|
||||
layout: 'normal',
|
||||
input: null,
|
||||
@@ -43,16 +48,44 @@ export default {
|
||||
methods: {
|
||||
init () {
|
||||
this.dialogVisible = true
|
||||
this.loadPasswords()
|
||||
},
|
||||
exitUser () {
|
||||
this.dialogVisible = false
|
||||
this.visible = false
|
||||
this.$emit('refreshUser', false)
|
||||
this.$store.dispatch('setSignOut')
|
||||
},
|
||||
async loadPasswords () {
|
||||
try {
|
||||
const response = await axios.get('../../static/password.txt', {responseType: 'text'})
|
||||
let fileContent = response.data || ''
|
||||
if (typeof fileContent !== 'string') {
|
||||
fileContent = String(fileContent)
|
||||
}
|
||||
this.passwords = fileContent.split('\n').map(line => line.trim()).filter(line => line)
|
||||
if (this.passwords.length === 0) {
|
||||
throw new Error('密码文件为空或格式不正确')
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message('加载密码文件失败')
|
||||
}
|
||||
},
|
||||
dataFormSubmit () {
|
||||
this.dialogVisible = false
|
||||
this.visible = false
|
||||
this.$emit('refreshUser', true)
|
||||
if (this.$store.getters.userInfo === 'true') {
|
||||
return
|
||||
}
|
||||
if (this.passwords.includes(this.dataForm.password)) {
|
||||
this.$store.dispatch('userInfo', 'true')
|
||||
this.$message({
|
||||
message: '登录成功',
|
||||
type: 'success'
|
||||
})
|
||||
} else {
|
||||
this.$message.error('登录失败')
|
||||
}
|
||||
this.dataForm = {password: ''}
|
||||
},
|
||||
handleClose (done) {
|
||||
this.visible = false
|
||||
|
||||
Reference in New Issue
Block a user