12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <template>
- <view class="login">
- <u-loading-page
- :loading="true"
- loading-text="登陆中..."
- :bg-color="$colors.bgColor"
- color="#ffffff"
- />
- </view>
- </template>
- <script>
- export default {
- components: {},
- data() {
- return {
- path: '/pages/index/index',
- query: {}
- }
- },
- computed: {},
- methods: {
- login() {
- // this.$loading('登陆中...')
- this.$api.user.login().then(async res => {
- this.$hideLoading()
- const { token, user_info } = res.data
- await this.$store.dispatch('user/token', token)
- await this.$store.dispatch('user/info', user_info)
- this.relaunch()
- }).catch(async() => {
- await this.$store.dispatch('user/token', null)
- await this.$store.dispatch('user/info', null)
- this.relaunch()
- })
- },
- relaunch() {
- uni.reLaunch({
- url: this.path,
- success() {
- console.log('-->success')
- },
- fail(err) {
- uni.reLaunch({
- url: '/pages/index/index'
- })
- console.log('-->error', err)
- }
- })
- }
- },
- onLoad(options) {
- console.log('-->data', options)
- if (this.$api.user.isLogin()) {
- uni.reLaunch({
- url: '/pages/index/index'
- })
- return
- }
- this.path = options.path ? options.path : this.path
- this.path = this.path.replace('//', '/')
- this.path = this.path.indexOf('/') !== 0 ? '/' + this.path : this.path
- const query = options.query ? JSON.parse(decodeURI(options.query)) : {}
- const queryArr = []
- for (const queryKey in query) {
- queryArr.push(`${queryKey}=${query[queryKey]}`)
- }
- this.path = this.path + '?' + queryArr.join('&')
- this.login()
- },
- onShow() {
- if (this.$api.user.isLogin()) {
- uni.reLaunch({
- url: '/pages/index/index'
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .login{
- }
- </style>
|