Password.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="hello">
  3. <Header> </Header>
  4. <el-container>
  5. <el-card class="center-card">
  6. <el-form status-icon label-width="0px" class="demo-ruleForm" @keyup.enter.native="onSubmit">
  7. <h2>{{$t('input_visit_password')}}</h2>
  8. <el-form-item label="" >
  9. <el-input type="password" auto-complete="off" v-model="password" :placeholder="$t('password')"></el-input>
  10. </el-form-item>
  11. <el-form-item label="" v-if="show_v_code">
  12. <el-input type="text" auto-complete="off" v-model="v_code" :placeholder="$t('verification_code')"></el-input>
  13. <img v-bind:src="v_code_img" class="v_code_img" v-on:click="change_v_code_img" >
  14. </el-form-item>
  15. <el-form-item label="" >
  16. <el-button type="primary" style="width:100%;" @click="onSubmit" >{{$t('submit')}}</el-button>
  17. </el-form-item>
  18. <el-form-item label="" >
  19. <router-link to="/user/login">{{$t('login')}}</router-link>
  20. &nbsp;&nbsp;&nbsp;
  21. </el-form-item>
  22. </el-form>
  23. </el-card>
  24. </el-container>
  25. <Footer> </Footer>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'Login',
  31. components : {
  32. },
  33. data () {
  34. return {
  35. password: '',
  36. v_code: '',
  37. v_code_img:DocConfig.server+'/api/common/verify',
  38. show_v_code:false
  39. }
  40. },
  41. methods: {
  42. onSubmit() {
  43. var item_id = this.$route.params.item_id ? this.$route.params.item_id : 0;
  44. var page_id = this.$route.query.page_id ? this.$route.query.page_id : 0 ;
  45. var that = this ;
  46. var url = DocConfig.server+'/api/item/pwd';
  47. var params = new URLSearchParams();
  48. params.append('item_id', item_id );
  49. params.append('page_id', page_id );
  50. params.append('password', this.password);
  51. params.append('v_code', this.v_code);
  52. that.axios.post(url, params)
  53. .then(function (response) {
  54. if (response.data.error_code === 0 ) {
  55. let redirect = decodeURIComponent(that.$route.query.redirect || ('/'+item_id));
  56. that.$router.replace({
  57. path: redirect
  58. });
  59. }else{
  60. if (response.data.error_code === 10206 || response.data.error_code === 10308) {
  61. that.show_v_code = true ;
  62. that.change_v_code_img() ;
  63. };
  64. that.$alert(response.data.error_message);
  65. }
  66. });
  67. },
  68. change_v_code_img(){
  69. var rand = '&rand='+Math.random();
  70. this.v_code_img += rand ;
  71. }
  72. },
  73. mounted() {
  74. /*给body添加类,设置背景色*/
  75. document.getElementsByTagName("body")[0].className="grey-bg";
  76. },
  77. beforeDestroy(){
  78. /*去掉添加的背景色*/
  79. document.body.removeAttribute("class","grey-bg");
  80. }
  81. }
  82. </script>
  83. <!-- Add "scoped" attribute to limit CSS to this component only -->
  84. <style scoped>
  85. .center-card a {
  86. font-size: 12px;
  87. }
  88. .center-card{
  89. text-align: center;
  90. }
  91. .v_code_img{
  92. margin-top: 20px;
  93. }
  94. </style>