1. 程式人生 > >點餐系統開發簡單總結

點餐系統開發簡單總結

本例子中使用vue腳手架構建SPA專案,詳細演示了vue元件開發,元件之間的引數傳遞、表單驗證、資料雙向繫結、列表渲染、使用VUEX進行全域性變數狀態控制、使用axios與webapi進行資料交換,此教程不僅僅講解了前端,還深入講解了資料庫設計及後臺管理系統開發,例如後臺登入模組、產品釋出模組、訂單管理模組、使用者管理等模組等,為了演示介面建立和呼叫,全程演示了webapi的建立和部署。通過本套教程的學習,你不僅可以學到vue的高階知識,還能學到資料庫設計、後臺管理系統開發、webapi的提供和呼叫等大型專案中必須掌握的關鍵技術。

歡迎廣大的程式設計愛好者和學員加微訊號yyjcw10000 或者 QQ:1416759661 進行技術交流。

先看介面:

基於VUE開發的,可能對於初學的朋友來說,有店困難,建議先學習下VUE基礎教程

下面將分別介紹各模組:

一、註冊模組:

<template>
<div class="wrapper">
<Header :isHideSettingBtn="true"/>
<div class="main">
  <div class="login">
    <p><input type="text" class="txt" v-model="LoginName" placeholder="使用者名稱" id="LoginName" /></p>
    <p><input type="password" class="txt" v-model="PassWord" placeholder="密碼" id="PassWord" /></p>
    <p><input type="text" class="txt" v-model="TrueName" placeholder="真實姓名" id="TrueName" /></p>
    <p><input type="text" class="txt" v-model="Tel" placeholder="手機號" id="Tel" /></p>
    <p><input type="button" @click="userreg" value="註冊" class="btnlogin" /></p>
    <p class="tipmsg">{{tipmsg}}</p>
  </div>
</div>
<Footer/>
</div>
</template>

<script>

import Header from '@/components/Header'
import Footer from '@/components/Footer'

export default {
  name: 'UserReg',
  data () {
    return {
      tipmsg:'',
      LoginName:'',
      PassWord:'',
      TrueName:'',
      Tel:''
    }
  },
  components:{
    Header,
    Footer
  },
  methods:{
    userreg:function () {
        var that=this;
        var webapiip=this.$store.getters.webapiip;
        this.tipmsg="";
        var LoginName=this.LoginName;
        var PassWord=this.PassWord;
        var TrueName=this.TrueName;
        var Tel=this.Tel;

        if(!(LoginName.length>0))
        {
            document.getElementById("LoginName").focus();
            this.tipmsg="請輸入使用者名稱!";
            return;
        }
        if(!(PassWord.length>0))
        {
            document.getElementById("PassWord").focus();
            this.tipmsg="請輸入密碼!";
            return;
        }
        if(!(TrueName.length>0))
        {
            document.getElementById("TrueName").focus();
            this.tipmsg="請輸入真實姓名!";
            return;
        }
        if(!(Tel.length>0))
        {
            document.getElementById("Tel").focus();
            this.tipmsg="請輸入電話號碼!";
            return;
        }


        this.$ajax({
               method: 'post',
               url: webapiip+'/api/diancan/PostAddUser',
               data: {
                  LoginName:LoginName,
                  PassWord:PassWord,
                  TrueName:TrueName,
                  Tel:Tel
               }
         }).then(res=>{
            console.log(res);

            if(res.data.flag=="0")
            {
                
                this.tipmsg=res.data.data;  
            }
            else
            {
                this.tipmsg="註冊成功";
                setTimeout(function(){
                    that.$router.push({
                      name: 'Login'
                    });
                },3000);
            }

            
               
         }).catch(err=>{
                  console.log("錯誤:"+err);
                  this.tipmsg="錯誤:"+err;
         });

    }

  }
}
</script>


<style scoped>

.wrapper{
   width:100%;
   height:100%;
}

.main{
  width:100%;
  height:calc(100% - 60px);
  position:fixed;
  top:30px;
  left:0px;
  overflow-y:scroll;
}

.login{
  width:calc(100% - 100px);
  height:200px;
  position:absolute;
  left:50px;
  top:calc(50% - 100px);
}
.main input{
    width:100%;
    height:32px;
    margin-top:5px;
    border:solid 1px #eee;
    border-radius:3px;
    outline:none;
}

.main input.txt{
    width:calc(100% - 5px);
    height:30px;
    margin-top:5px;
    padding-left:3px;
}

.btnlogin{
  background-color:#3CB371;
  color:#fff;
  cursor:pointer;
}
.tipmsg{
  color:red;
}
</style>
 

二、登入模組:

<template>
<div class="wrapper">
<Header :isHideBackBtn="true" :isHideSettingBtn="true"/>
<div class="main">
  <div class="login">
    <p><input type="text" class="txt" v-model="username" placeholder="使用者名稱" id="username" /></p>
    <p><input type="password" class="txt" v-model="password" placeholder="密碼" id="password"/></p>
    <p><input type="button" value="登入" @click="login" class="btnlogin" /></p>
    <p><input type="button" value="註冊" @click="userreg" class="btnreg" /></p>
    <p class="tipmsg">{{tipmsg}}</p>
  </div>
</div>
<Footer/>
</div>
</template>

<script>

import Header from '@/components/Header'
import Footer from '@/components/Footer'

export default {
  name: 'Login',
  created(){
    this.$store.commit('SET_APPTITLE',"快易樂點餐系統v1.0-登入");

  },
  data () {
    return {
      tipmsg:'',
      username:'',
      password:''
    }
  },
  components:{
    Header,
    Footer
  },
  methods:{
    userreg:function() {
      this.$router.push({name: 'UserReg'});
    },
    login:function(){
        var username=this.username;
        var password=this.password;
        var deskid=this.$route.query.id;
        if(!(username.length>0))
        {
            this.tipmsg="請輸入使用者名稱";
            document.getElementById("username").focus();
            return;
        }

        if(!(password.length>0))
        {
            this.tipmsg="請輸入密碼";
            document.getElementById("password").focus();
            return;
        }

        if(!deskid)
        {
            deskid=1;
        }
        var webapiip=this.$store.getters.webapiip;
        //向webapi發起一個ajax請求,驗證使用者名稱和密碼
        this.$ajax({
               method: 'post',
               url:webapiip+'/api/diancan/PostLogin',
               data: {
                  LoginName:username,
                  PassWord:password
               }
         }).then(res=>{

            if(res.data.data.ds.length>0)
            {
                //登入成功
                this.tipmsg="";
                var currentuser=res.data.data.ds[0];
                localStorage.setItem("userid",currentuser.ID);
                localStorage.setItem("TrueName",currentuser.TrueName);
                localStorage.setItem("Tel",currentuser.Tel);
                localStorage.setItem("deskid",deskid);
                this.$router.push({
                      name: 'FoodList',
                      params: {
                        userId: currentuser.ID
                      }
                });
                
            }
            else
            {
                //登入失敗
                this.tipmsg="錯誤:使用者名稱或密碼錯誤";
            }

            console.log(res.data.data.ds[0]);
               
         }).catch(err=>{
                  console.log("錯誤:"+err);
                  this.tipmsg="錯誤:"+err;
         });


    }

  }

}
</script>


<style scoped>

.wrapper{
   width:100%;
   height:100%;
}

.main{
  width:100%;
  height:calc(100% - 60px);
  position:fixed;
  top:30px;
  left:0px;
  overflow-y:scroll;
}

.login{
  width:calc(100% - 100px);
  height:200px;
  position:absolute;
  left:50px;
  top:calc(50% - 100px);
}
.main input{
    width:100%;
    height:32px;
    margin-top:5px;
    border:solid 1px #eee;
    border-radius:3px;
    outline:none;
}

.main input.txt{
    width:calc(100% - 5px);
    height:30px;
    margin-top:5px;
    padding-left:3px;
}

.btnlogin{
  background-color:#3CB371;
  color:#fff;
  cursor:pointer;
}

.tipmsg{
  color:red;
}

</style>

後續模組陸續更新。

最近開發比較忙碌,總是抽不出時間,可以先看下