转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeyemianzhongdingxiang59/

在我们正常的浏览网站的时候,未登录点击vip专区的时候,需要登录,登录后还会回到最初要进入的网站,这就是页面重定向,在小程序里面也需要完成这样的功能。源码:https://github.com/limingios/wxProgram.git 中No.15

小程序代码

对于搜索,可以类似淘宝的功能,无需登录就可以进行搜索,但是文件上传这个功能就需要进行登录后才可以进行上传,登录后在跳转到原来的页面进行操作。

  • 增加data中的默认页面对象,本页面的回调地址
var videoUtils = require('../../utils/videoUtils.js')
const app = getApp()
Page({ data: {
cover:'cover',
videoContext:"",
videoInfo:{},
videId:'',
src:''
}, showSearch:function(){
wx.navigateTo({
url: '../videoSearch/videoSearch',
})
},
onLoad:function(params){
var me = this;
me.videoContext = wx.createVideoContext('myVideo', me);
var videoInfo = JSON.parse(params.videoInfo);
var videoWidth = videoInfo.videoWidth;
var videoHeight = videoInfo.videoHeight;
var cover = 'cover';
if (videoWidth > videoHeight){
cover = '';
}
me.setData({
videId: videoInfo.id,
src: app.serverUrl + videoInfo.videoPath,
videoInfo: videoInfo,
cover: cover
}) },
showIndex:function(){
wx.redirectTo({
url: '../index/index',
})
}, onShow:function(){
var me = this;
me.videoContext.play();
},
onHide:function(){
var me = this;
me.videoContext.pause();
},
upload:function(){ var me = this;
var userInfo = app.getGlobalUserInfo(); var videoInfo = JSON.stringify(me.data.videoInfo);
var realUrl = '../videoInfo/videoInfo#videoInfo@' + videoInfo; if (userInfo.id == '' || userInfo.id == undefined) {
wx.navigateTo({
url: '../userLogin/userLogin?realUrl=' + realUrl,
})
} else {
videoUtils.uploadVideo();
} },
showMine: function () {
var me = this;
var userInfo = app.getGlobalUserInfo(); var videoInfo = JSON.parse if (userInfo.id == '' || userInfo.id == undefined){
wx.navigateTo({
url: '../userLogin/userLogin',
})
}else{
wx.navigateTo({
url: '../mine/mine',
})
} },
})

登录页面的解析控制

const app = getApp()

Page({
data: {
realUrl:''
},
onLoad:function(params){
var realUrl = params.realUrl;
var me = this;
realUrl = realUrl.replace(/#/g,"?");
realUrl = realUrl.replace(/@/g, "=");
me.setData({
realUrl: realUrl
})
},
doLogin: function (e) {
var formObject = e.detail.value;
var username = formObject.username;
var password = formObject.password;
var me = this;
// 简单验证
if (username.length == 0 || password.length == 0) {
wx.showToast({
title: '用户名或密码不能为空',
icon: 'none',
duration: 3000
})
} else {
wx.showLoading({
title: '正在登录中。。。'
});
wx.request({
url: app.serverUrl + "/login",
method: "POST",
data: {
username: username,
password: password
},
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
console.log(res.data); var status = res.data.status;
wx.hideLoading();
if (status == 200) {
wx.showToast({
title: "用户登陆成功~!",
icon: 'none',
duration: 3000
})
// app.userInfo = res.data.data;
app.setGlobalUserInfo(res.data.data); var realUrl = me.data.realUrl; if (realUrl != null && realUrl != '' && realUrl != undefined){
wx.redirectTo({
url: realUrl,
})
}else{
wx.redirectTo({
url: '../mine/mine',
})
} } else if (status == 500) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 3000
})
}
}
})
}
},
goRegisterPage: function (e) {
wx.redirectTo({
url: '../userRegister/userRegister',
})
}
})

PS:页面重定向只是一种手段,有很多是通过后台的方式来进行控制的,下次给老铁说下springboot的拦截器。

「小程序JAVA实战」小程序的页面重定向(60)的更多相关文章

  1. 「小程序JAVA实战」小程序的flex布局(22)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...

  2. 「小程序JAVA实战」小程序的留言和评价功能(70)

    转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...

  3. 「小程序JAVA实战」小程序的举报功能开发(68)

    转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...

  4. 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...

  5. 「小程序JAVA实战」小程序的关注功能(65)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...

  6. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  7. 「小程序JAVA实战」小程序的springboot后台拦截器(61)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...

  8. 「小程序JAVA实战」小程序首页视频(49)

    转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...

  9. 「小程序JAVA实战」小程序视频封面处理(48)

    转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...

随机推荐

  1. 微信小程序纯css制作圆形进度条所遇到的问题

    wrapBox:最外层盒子,背景色为进度条的颜色 leftBox/rightBox:半宽等长 左/右浮动的盒子,背景色为灰色 roundMask:居中的盒子 用来遮盖leftBox和rightBox ...

  2. Mybatis generator 配置

    mybatis-generator.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...

  3. IOS-网络(GET请求和POST请求、HTTP通信过程、请求超时、URL转码)

    // // ViewController.m // IOS_0129_HTTP请求 // // Created by ma c on 16/1/29. // Copyright © 2016年 博文科 ...

  4. this 知多少

    js 中的this 到底指向哪里涅,学习js的过程中,肯定有不少小伙伴们调入this的大坑中,究其原因,this的指向在函数创建的时候是决定不了的,在调用的时候才能决定,谁调用的就指向谁...曾经,我 ...

  5. jQuery中 attr和Prop的区别

    出自这里: http://www.365mini.com/page/jquery_noconflict.htm 在jQuery中,attr()函数和prop()函数都用于设置或获取指定的属性,它们的参 ...

  6. VS2017 IDE中发布自包含(SCD)DotNET Core项目

    根据Stack Overflow上的一个回答得知,这项功能目前VS2017并不具备,但你可以通过如下方法发布自包含项目: 1.项目文件(.csproj)中添加RuntimeIdentifier配置项, ...

  7. 6-19 Count Connected Components(20 分)

    Write a function to count the number of connected components in a given graph. Format of functions: ...

  8. 《FDTD electromagnetic field using MATLAB》读书笔记之 Figure 1.14

    背景: 基于公式1.42(Ez分量).1.43(Hy分量)的1D FDTD实现. 计算电场和磁场分量,该分量由z方向的电流片Jz产生,Jz位于两个理想导体极板中间,两个极板平行且向y和z方向无限延伸. ...

  9. CH3201 Hankson的趣味题

    题意 3201 Hankson的趣味题 0x30「数学知识」例题 描述 Hanks博士是BT(Bio-Tech,生物技术)领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson ...

  10. prisma graphql 工具基本使用

    项目使用docker-compose mysql 运行 安装 npm insatll -g prisma or yarn global add prisma 创建代码 项目结构 ├── README. ...