qirong
2024-02-28 68921acbd1509d7cacef9ebdc4c0f764433ca252
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
  <div class="login-page">
    <!-- 导航栏部分 -->
<!--    <van-nav-bar title="面经登录" />-->
    <van-dialog
      v-model="showDing"
      title="下载中"
      :show-cancel-button="false"
      :show-confirm-button="false"
    >
      <van-circle
        v-model="currentRate"
        :rate="0"
        :speed="100"
        :text="text"
      />
    </van-dialog>
 
  <div class="login-van-fie">
    <van-field
      v-model="password"
      placeholder="请输入提取码"
      :rules="[
        { required: true, message: '请填写提取码' },
        { pattern: /^\w{6,}$/, message: '提取码至少是6位字符' }
        ]"
    />
  </div>
      <div style="margin: 16px;" class="login-van-btn">
<!--        <van-button-->
<!--          block-->
<!--          type="primary"-->
<!--          native-type="submit"-->
<!--          @click="onstest"-->
<!--        >确认0</van-button>-->
<!--        <van-button-->
<!--          block-->
<!--          type="primary"-->
<!--          native-type="submit"-->
<!--          @click="onSubPwd"-->
<!--        >确认1</van-button>-->
        <van-button
          block
          type="primary"
          native-type="submit"
          @click="donwn"
        >确认</van-button>
      </div>
    <div v-if="downXs">
      <p>
 
      </p>
    </div>
<!--    <router-link class="link" to="/register">注册账号</router-link>-->
  </div>
</template>
 
<script>
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'
 
export default {
  name: 'login-page',
  data () {
    return {
      downXs: false,
      mytime: null,
      currentRate: 0,
      text: '0%',
      showDing: false,
      dowRrl: '',
      username: '',
      password: '',
      apptoken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZENhcmQiOiI1MTAxMTMxOTg2MDUwNzA0MVgiLCJhcHBLZXkiOiI5MWEzZjM3NDQ0NWM0MmQyYjA3MGJiMTI1NzgwYzA3ZCIsIklNRUkiOiJlNzkwZDM0ZTVlNGNkMTg2IiwiZXhwIjoxNzA0OTAyMzk5LCJpYXQiOjE3MDQ4NDU0MDJ9.8g08LXtg8QZzksnWT5xqXmhWzR8FfVaWDjBRPOdWgVY'
    }
  },
 
  mounted () {
    // console.log('mounted')
    const me = this
    // eslint-disable-next-line
    window["downloadCompleted"] = (val,res) => {
      me.downloadCompletedBackToday(val, res) // 这个也就是定义的方法
    }
    me.getApptoken()
  },
  methods: {
    downloadCompletedBackToday (val, res) {
      // eslint-disable-next-line eqeqeq
      if (val == 0) {
        this.downXs = true
        this.showDing = false
        this.$toast.fail('下载成功!')
        this.currentRate = 0
        clearInterval(this.mytime)
        // eslint-disable-next-line eqeqeq
      } else if (val == 2) {
        this.showDing = false
        this.$toast.fail('提取码错误!')
        this.currentRate = 0
        clearInterval(this.mytime)
      } else {
        this.$toast.fail('下载失败!')
        this.showDing = false
        this.currentRate = 0
        clearInterval(this.mytime)
      }
    },
    donwn () {
      // eslint-disable-next-line eqeqeq
      if (this.password == '') {
        this.$toast.fail('请填写提取码')
        return
      }
      clearInterval(this.mytime)
      this.currentRate = 0
      this.showDing = true
      this.mytime = setInterval(() => {
        this.currentRate++
        if (this.currentRate >= 100) {
          clearInterval(this.mytime)
          // this.showDing = false
        }
        this.text = this.currentRate.toFixed(0) + '%'
      }, 1000)
      const url = 'http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/' + `${this.apptoken}/12345678/${this.password}`
      // const url = 'http://162.14.79.111:8080/resource/oss/download' + `/12345678/${this.password}`
      window.JavaScriptMe.downFileUrl(url)
    },
    onstests () {
      const elemIF = document.createElement('iframe')
      // elemIF.src = 'http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/' + `${this.apptoken}/12345678/${this.password}`
      elemIF.src = 'http://162.14.79.111:8080/resource/oss/download' + `/12345678/${this.password}`
      console.log(elemIF.src)
      elemIF.style.display = 'none'
      document.body.appendChild(elemIF)
    },
    onstest () {
      const url = 'http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/' + `${this.apptoken}/12345678/${this.password}`
      // const url = 'http://162.14.79.111:8080/resource/oss/download' + `/12345678/${this.password}`
 
      const a = document.createElement('a')
      a.href = url
      a.download = 'test222'
      a.click()
    },
    onSubPwd () {
      const x = new window.XMLHttpRequest()
      // x.open('GET', 'http://162.14.79.111:8080/resource/oss/download' + `/12345678/${this.password}`, true)
      x.open('GET', 'http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/' + `${this.apptoken}/12345678/${this.password}`, true)
      x.responseType = 'blob'
      x.onload = () => {
        const url = window.URL.createObjectURL(x.response)
        const a = document.createElement('a')
        a.href = url
        a.download = 'test'
        a.click()
      }
      x.send()
 
      // http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/{token}
      // fetch('http://esb.ydjw.sc/service/api/56e038d545bb4fa3834d03c368d74118/' + `${this.apptoken}/12345678/${this.password}`, {
      //   method: 'Get',
      //   mode: 'cors',
      //   headers: {
      //     'Content-Type': 'application/json;charset=utf-8;'
      //   },
      //   responseType: 'blob',
      // }).then(res => {
      //   console.log(res)
      // })
    },
    getApptoken () {
      // window.JavaScriptMe.getAppCenterToken()
      this.apptoken = JSON.parse(window.JavaScriptMe.getAppCenterToken())
      // localStorage.setItem('appkey', appkey)
    },
    async  onSubmit (values) {
      // console.log('submit', values)
      const res = await login(values)
      // console.log(res)
      // 存token
      setToken(res.data.token)
      this.$toast.success('登录成功!')
      this.$router.push('/')
    }
  }
}
</script>
 
<style lang="less" scoped>
/deep/.van-dialog__content{
  text-align: center;
  margin: 1rem 0;
}
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
.login-page{
  min-height: 100vh;
}
.login-van-fie{
  padding-top: 50%;
}
.van-cell{
  border: 1px solid #ededed;
  margin: 0 1rem;
  border-radius: 40px;
  width: 90%;
}
.van-button{
  margin-top: 3rem;
  border-radius: 40px;
}
</style>