Skip to content

Commit

Permalink
优化了与后端通信的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
youranreus committed Dec 24, 2020
1 parent fa3fbd1 commit 3b3fcc3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
Binary file modified X/database.db
Binary file not shown.
13 changes: 3 additions & 10 deletions X/index.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<?php
header('Content-Type:application/json; charset=utf-8');
header('Access-Control-Allow-Origin:*');
//截取链接&参数
$uri = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if(isset($_SERVER["QUERY_STRING"])){
$params = $_SERVER["QUERY_STRING"];
}else{
$params = "";
}
require 'main.class.php';
$X = new main();
if(isset($uri[2])){
call_user_func_array(array($X, $uri[2]), array($params));
if(isset($_GET['action'])){
call_user_func(array($X, $_GET['action']));
}else{
call_user_func_array(array($X, 'hello'), array($params));
call_user_func(array($X, 'hello'));
}


Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
<script src="https://cdn.bootcdn.net/ajax/libs/js-cookie/latest/js.cookie.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/marked/1.2.2/marked.min.js"></script>
<script src="main.js?v=2.4" type="module"></script>
<script src="main.js?v=2.6" type="module"></script>
</html>
29 changes: 19 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ let machine_component = Vue.component('machine_component', {
if (this.logged !== 'true') {
this.$router.push({path: '/u'})
}
axios.get('/X/getMachineList?type=all')
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=getMachineList&type=all')
.then((response) => {
if (response.data.length !== 0) {
this.machines = response.data;
Expand Down Expand Up @@ -92,7 +93,8 @@ let u_component = Vue.component('u_component', {
,
methods: {
login: function () {
axios.get('/X/login?key=' + this.pwd)
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=login&key=' + this.pwd)
.then((response) => {
if (response.data.msg === 'true') {
Cookies.set('UserStatus', 'true', {expires: 7});
Expand Down Expand Up @@ -199,14 +201,15 @@ let p_component = Vue.component('p_component', {
if (this.logged !== 'true') {
this.$router.push({path: '/u'})
}
axios.get('/X/getMachineList')
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=getMachineList')
.then((response) => {
if (response.data.length !== 0) {
this.machines = response.data;
this.isEmpty = false;
}
})
axios.get('/X/getInfo')
axios.get(url = 'X/index.php?action=getInfo')
.then((response)=>{
if (response.data.length !== 0) {
this.info = response.data;
Expand Down Expand Up @@ -274,7 +277,8 @@ let machine_detail_component = Vue.component('machine_detail_component', {
},
methods:{
getDetail: function(){
axios.get('/X/getMachineDetail?id=' + this.$route.params.id)
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=getMachineDetail&id=' + this.$route.params.id)
.then((response)=>{
this.machineDetail = response.data[0]
document.getElementById('machine-otherDetail-content').innerHTML = marked(this.machineDetail["info"]);
Expand Down Expand Up @@ -445,7 +449,8 @@ let machine_edit_component = Vue.component('Machine_edit_component',{
},
methods:{
getDetail: function(){
axios.get('/X/getMachineDetail?id=' + this.$route.params.id)
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=getMachineDetail&id=' + this.$route.params.id)
.then((response)=>{
this.machineDetail = response.data[0]
})
Expand All @@ -458,7 +463,8 @@ let machine_edit_component = Vue.component('Machine_edit_component',{
},
update: function(){
if(this.machineDetail['name'] !== '' && this.machineDetail['liked'] !== '' && this.machineDetail['deadline'] !== '' && this.machineDetail['location'] !== '' && this.machineDetail['fee'] !== '' && this.machineDetail['cycle'] !== '' && this.machineDetail['auto'] !== '' && this.machineDetail['panel'] !== '' && this.machineDetail['info'] !== '' && this.machineDetail['HOST'] !== '' && this.machineDetail['ip'] !== ''){
axios.get('/X/updateMachineDetail?id='+this.$route.params.id + '&name='+this.machineDetail['name']+'&liked='+this.machineDetail['liked']+'&deadline='+this.machineDetail['deadline']+'&location='+this.machineDetail['location']+'&fee='+this.machineDetail['fee']+'&cycle='+this.machineDetail['cycle']+'&auto='+this.machineDetail['auto']+'&panel='+this.machineDetail['panel']+'&info='+this.machineDetail['info']+'&HOST='+this.machineDetail['HOST']+'&ip='+this.machineDetail['ip'])
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=updateMachineDetail&id='+this.$route.params.id + '&name='+this.machineDetail['name']+'&liked='+this.machineDetail['liked']+'&deadline='+this.machineDetail['deadline']+'&location='+this.machineDetail['location']+'&fee='+this.machineDetail['fee']+'&cycle='+this.machineDetail['cycle']+'&auto='+this.machineDetail['auto']+'&panel='+this.machineDetail['panel']+'&info='+this.machineDetail['info']+'&HOST='+this.machineDetail['HOST']+'&ip='+this.machineDetail['ip'])
.then((response)=>{
if(response.data === 1){
alert("编辑成功")
Expand Down Expand Up @@ -630,7 +636,8 @@ let machine_add_component = Vue.component('Machine_add_component',{
},
add: function(){
if(this.machineDetail['name'] !== '' && this.machineDetail['liked'] !== '' && this.machineDetail['deadline'] !== '' && this.machineDetail['location'] !== '' && this.machineDetail['fee'] !== '' && this.machineDetail['cycle'] !== '' && this.machineDetail['auto'] !== '' && this.machineDetail['panel'] !== '' && this.machineDetail['info'] !== '' && this.machineDetail['HOST'] !== '' && this.machineDetail['ip'] !== ''){
axios.get('/X/AddMachine?id='+this.$route.params.id + '&name='+this.machineDetail['name']+'&liked='+this.machineDetail['liked']+'&deadline='+this.machineDetail['deadline']+'&location='+this.machineDetail['location']+'&fee='+this.machineDetail['fee']+'&cycle='+this.machineDetail['cycle']+'&auto='+this.machineDetail['auto']+'&panel='+this.machineDetail['panel']+'&info='+this.machineDetail['info']+'&HOST='+this.machineDetail['HOST']+'&ip='+this.machineDetail['ip'])
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=AddMachine&id='+this.$route.params.id + '&name='+this.machineDetail['name']+'&liked='+this.machineDetail['liked']+'&deadline='+this.machineDetail['deadline']+'&location='+this.machineDetail['location']+'&fee='+this.machineDetail['fee']+'&cycle='+this.machineDetail['cycle']+'&auto='+this.machineDetail['auto']+'&panel='+this.machineDetail['panel']+'&info='+this.machineDetail['info']+'&HOST='+this.machineDetail['HOST']+'&ip='+this.machineDetail['ip'])
.then((response)=>{
if(response.data === 1){
alert("添加成功")
Expand Down Expand Up @@ -685,7 +692,8 @@ let machine_delete_component = Vue.component('machine_delete_component',{
},
methods:{
getDetail: function(){
axios.get('/X/getMachineDetail?id=' + this.$route.params.id)
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=getMachineDetail&id=' + this.$route.params.id)
.then((response)=>{
this.machineDetail = response.data[0]
})
Expand All @@ -696,7 +704,8 @@ let machine_delete_component = Vue.component('machine_delete_component',{
},
ensureDelete: function(){
if(this.input === 'yes'){
axios.get('/X/DeleteMachine?id='+this.$route.params.id)
let url = window.location.href.replace(window.location.hash,'');
axios.get(url + 'X/index.php?action=DeleteMachine&id='+this.$route.params.id)
.then((response)=>{
if(response.data === 1){
alert('删除成功~')
Expand Down

0 comments on commit 3b3fcc3

Please sign in to comment.