use raw api data to fill vm

This commit is contained in:
virusdefender 2017-01-26 18:51:26 +08:00
parent eae0b78a25
commit 49828094fa
4 changed files with 59 additions and 74 deletions

View File

@ -51,7 +51,6 @@
"function-bind": "^1.0.2",
"html-webpack-plugin": "^2.8.1",
"http-proxy-middleware": "^0.17.2",
"humps": "^2.0.0",
"inject-loader": "^2.0.1",
"isparta-loader": "^2.0.0",
"json-loader": "^0.5.4",

View File

@ -1,7 +1,7 @@
<template>
<div class="view">
<Panel title="Create Contest">
<el-form label-position="top" label-width="70px">
<el-form label-position="top">
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="Title" required>
@ -16,7 +16,7 @@
<el-col :span="8">
<el-form-item label="Start Time" required>
<el-date-picker
v-model="startTime"
v-model="start_time"
type="datetime"
placeholder="Start Time">
</el-date-picker>
@ -25,7 +25,7 @@
<el-col :span="8">
<el-form-item label="End Time" required>
<el-date-picker
v-model="endTime"
v-model="end_time"
type="datetime"
placeholder="End Time">
</el-date-picker>
@ -37,22 +37,22 @@
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Contest Rule Type" required>
<el-radio class="radio" v-model="ruleType" label="ACM">ACM</el-radio>
<el-radio class="radio" v-model="ruleType" label="OI">OI</el-radio>
<el-form-item label="Contest Rule Type">
<el-radio class="radio" v-model="rule_type" label="ACM">ACM</el-radio>
<el-radio class="radio" v-model="rule_type" label="OI">OI</el-radio>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Real Time Rank" required>
<el-form-item label="Real Time Rank">
<el-switch
v-model="realTimeRank"
v-model="real_time_rank"
on-color="#13ce66"
off-color="#ff4949">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Status" required>
<el-form-item label="Status">
<el-switch
v-model="visible"
on-text=""
@ -71,7 +71,6 @@
import api from '../../api.js'
import Panel from '../../components/Panel.vue'
import Simditor from '../../components/Simditor.vue'
import humps from 'humps'
export default{
components: {
Panel,
@ -81,20 +80,19 @@
return {
title: '',
description: '',
startTime: '',
endTime: '',
ruleType: 'ACM',
start_time: '',
end_time: '',
rule_type: 'ACM',
password: '',
realTimeRank: true,
real_time_rank: true,
visible: true
}
},
mounted () {
},
methods: {
saveContest () {
console.log(humps.decamelizeKeys(this.$data))
api.createContest(humps.decamelizeKeys(this.$data))
api.createContest(this.$data).then(res => {
this.$router.push('/contest')
}).catch(() => {})
}
}
}

View File

@ -61,23 +61,29 @@
</Panel>
<!--对话框-->
<el-dialog :title="announcementDialogTitle" @open="onOpenEditDialog" v-model="showEditAnnouncementDialog">
<el-input
v-model="announcement.title"
placeholder="Title" class="title-input">
</el-input>
<Simditor v-model="announcement.content"></Simditor>
<div class="visible-box">
<span>Status</span>
<el-switch
v-model="announcement.visible"
on-text=""
off-text="">
</el-switch>
</div>
<el-form label-position="top">
<el-form-item label="Title" required>
<el-input
v-model="announcement.title"
placeholder="Title" class="title-input">
</el-input>
</el-form-item>
<el-form-item label="Content" required>
<Simditor v-model="announcement.content"></Simditor>
</el-form-item>
<div class="visible-box">
<span>Status</span>
<el-switch
v-model="announcement.visible"
on-text=""
off-text="">
</el-switch>
</div>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click.native="showEditAnnouncementDialog = false">Cancel</el-button>
<el-button type="primary" @click.native="submit(),showEditAnnouncementDialog = false">Submit</el-button>
</span>
<el-button @click.native="showEditAnnouncementDialog = false">Cancel</el-button>
<el-button type="primary" @click.native="submit()">Submit</el-button>
</span>
</el-dialog>
</div>
</template>
@ -152,12 +158,14 @@
submit () {
if (this.currentAnnouncementId) {
api.modifyAnnouncement(this.currentAnnouncementId, this.announcement.title, this.announcement.content, this.announcement.visible).then(res => {
this.showEditAnnouncementDialog = false
this.getAnnouncementList((this.currentPage - 1) * this.pageSize, this.pageSize)
})
}).catch(() => {})
} else {
api.createAnnouncement(this.announcement.title, this.announcement.content, this.announcement.visible).then(res => {
this.showEditAnnouncementDialog = false
this.getAnnouncementList((this.currentPage - 1) * this.pageSize, this.pageSize)
})
}).catch(() => {})
}
},
//

View File

@ -4,22 +4,22 @@
<el-form label-position="left" label-width="70px" :model="smtp">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="Server">
<el-form-item label="Server" required>
<el-input v-model="smtp.server" placeholder="SMTP Server Address"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="Port">
<el-form-item label="Port" required>
<el-input type="number" v-model="smtp.port" placeholder="SMTP Server Port"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="Email">
<el-form-item label="Email" required>
<el-input type="email" v-model="smtp.email" placeholder="Account Used To Send Email"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="Password">
<el-form-item label="Password" label-width="90px" required>
<el-input v-model="smtp.password" type="password" placeholder="SMTP Server Password"></el-input>
</el-form-item>
</el-col>
@ -41,22 +41,22 @@
<el-form label-position="left" label-width="100px" ref="form" :model="websiteConfig">
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="Base URL">
<el-input v-model="websiteConfig.baseURL" placeholder="Website Base Url"></el-input>
<el-form-item label="Base Url" required>
<el-input v-model="websiteConfig.base_url" placeholder="Website Base Url"></el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Name">
<el-form-item label="Name" required>
<el-input v-model="websiteConfig.name" placeholder="Website Name"></el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Shortcut">
<el-input v-model="websiteConfig.nameShortcut" placeholder="Website Name Shortcut"></el-input>
<el-form-item label="Shortcut" required>
<el-input v-model="websiteConfig.name_shortcut" placeholder="Website Name Shortcut"></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="Footer">
<el-form-item label="Footer" required>
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="websiteConfig.footer"
placeholder="Website Footer HTML"></el-input>
</el-form-item>
@ -65,7 +65,7 @@
<el-col :span="12">
<el-form-item label="Allow Register" label-width="200px">
<el-switch
v-model="websiteConfig.allowRegister"
v-model="websiteConfig.allow_register"
on-color="#13ce66"
off-color="#ff4949">
</el-switch>
@ -74,7 +74,7 @@
<el-col :span="12">
<el-form-item label="Submission List Show All" label-width="200px">
<el-switch
v-model="websiteConfig.submissionListShowAll"
v-model="websiteConfig.submission_list_show_all"
on-color="#13ce66"
off-color="#ff4949">
</el-switch>
@ -91,6 +91,7 @@
<script>
import api from '../../api.js'
import Panel from '../../components/Panel.vue'
export default{
components: {
Panel
@ -105,14 +106,7 @@
email: 'email@example.com',
tls: true
},
websiteConfig: {
baseURL: '',
name: '',
nameShortcut: '',
footer: '',
allowRegister: false,
submissionListShowAll: false
}
websiteConfig: {}
}
},
mounted () {
@ -125,14 +119,8 @@
}
})
api.getWebsiteConfig().then(res => {
let data = res.data.data
this.websiteConfig.baseURL = data.base_url
this.websiteConfig.name = data.name
this.websiteConfig.nameShortcut = data.name_shortcut
this.websiteConfig.footer = data.footer
this.websiteConfig.allowRegister = data.allow_register
this.websiteConfig.submissionListShowAll = data.submission_list_show_all
})
this.websiteConfig = res.data.data
}).catch(() => {})
},
methods: {
saveSMTPConfig () {
@ -143,15 +131,7 @@
}
},
updateWebsiteConfig () {
let config = this.websiteConfig
let data = {base_url: config.baseURL,
name: config.name,
name_shortcut: config.nameShortcut,
footer: config.footer,
allow_register: config.allowRegister,
submission_list_show_all: config.submissionListShowAll
}
api.updateWebsiteConfig(data)
api.updateWebsiteConfig(this.websiteConfig).then(() => {}).catch(() => {})
}
}
}