123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- var util = require('../../utils/util.js');
- var location = require('../../utils/Location.js');
- var app = getApp();
- Component({
- properties: {
- needAuth: {
- type: Boolean,
- value: false
- },
- needPosition: {
- type: Boolean,
- value: true
- },
- navBackUrl: {
- type: String,
- value: '',
- observer: function (t) {
- if (t) app.globalData.navBackUrl = t;
- }
- }
- },
- attached: function () {
- this.setData({
- skin: getApp().globalData.skin,
- })
- this.getBg();
- },
- data: {
- nickname:'',
- avatarUrl:'../../images/sctx.png',
- btnLoading: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo')
- },
- methods: {
- agree:function(){
- console.log("用户同意隐私授权, 接下来可以调用隐私协议中声明的隐私接口")
- },
-
- disagree:function(){
- console.log("用户拒绝隐私授权, 未同意过的隐私协议中的接口将不能调用")
- // this.triggerEvent("cancel");
- wx.showToast({
- title: '需同意后才可以继续使用'+app.globalData.title+'小程序',
- duration: 2000,
- icon:"none"
- })
- },
- onChooseAvatar(e) {
- console.log(e.detail,'0000000000')
- this.setData({
- avatarUrl:e.detail.avatarUrl
- })
- },
- getBg: function () {
- let that = this;
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'index.get_newauth_bg'
- },
- dataType: 'json',
- success: function (res) {
- that.setData({ loaded: true })
- if (res.data.code == 0) {
- let { newauth_bg_image, newauth_confirm_image, newauth_cancel_image } = res.data.data;
- that.setData({ newauth_bg_image, newauth_confirm_image, newauth_cancel_image })
- }
- }
- })
- },
- close: function () {
- this.triggerEvent("cancel");
- },
- bindGetUserInfo: function (t) {
- var that = this;
- if (!this.data.btnLoading) {
- var n = t.detail;
- if (this.setData({ btnLoading: true }), "getUserInfo:ok" === n.errMsg) {
- util.login_prosime(that.data.needPosition).then(function () {
- console.log("授权成功")
- that.setData({ btnLoading: false });
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- duration: 2000
- })
- that.triggerEvent("authSuccess");
- app.globalData.changedCommunity = true;
- //检查获取位置权限
- that.data.needPosition && location.getGps();
- }).catch(function () {
- that.triggerEvent("cancel");
- console.log('授权失败');
- })
- } else {
- wx.showToast({
- title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
- icon: "none"
- });
- this.triggerEvent("cancel");
- this.setData({ btnLoading: false });
- }
- }
- },
- getProfile: function() {
- var that = this;
- console.log(this.data.nickname,'9999')
- //非空验证
- if(this.data.avatarUrl=='../../images/sctx.png'){
- wx.showToast({
- title: "请上传头像",
- icon: "none"
- });
- return false;
- }
- if(this.data.nickname==''){
- wx.showToast({
- title: "",
- icon: "none"
- });
- return false;
- }
- wx.uploadFile({
- url: app.util.url('entry/wxapp/index', {'m':'lionfish_comshop','controller':'goods.doPageUpload'}),
- filePath: that.data.avatarUrl,
- name: 'upfile',
- formData: {
- 'name':that.data.avatarUrl
- },
- header: {
- 'content-type': 'multipart/form-data'
- },
- success: function (res) {
- var data = JSON.parse(res.data);
- console.log(data.image_o,'000000000000000000000')
- that.setData({
- avatarUrl:data.image_o
- })
- }
- })
- console.log(wx.canIUse("getUserProfile"));
- if (!that.data.btnLoading) {
- // if(wx.canIUse("getUserProfile")) {
- wx.getUserProfile({
- desc: "获取你的昵称、头像、地区及性别",
- success: function (msg) {
-
- var userInfo = msg.userInfo
- userInfo['nickName']=that.data.nickname
- userInfo['avatarUrl']=that.data.avatarUrl
- console.log( userInfo,'898989')
- wx.setStorage({
- key: "userInfo",
- data: userInfo
- })
- that.setData({ btnLoading: true });
- util.login_prosime(that.data.needPosition, userInfo).then( res => {
- console.log("授权成功")
- that.setData({ btnLoading: false });
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- duration: 2000
- })
- that.triggerEvent("authSuccess", res);
- app.globalData.changedCommunity = true;
- //检查获取位置权限
- that.data.needPosition && location.getGps();
- }).catch(function () {
- that.triggerEvent("cancel");
- console.log('授权失败');
- })
- },
- fail: ()=>{
- wx.showToast({
- title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
- icon: "none"
- });
- that.triggerEvent("cancel");
- that.setData({ btnLoading: false });
- }
- })
- }
- // } else {
- // wx.showModal({
- // title: '提示',
- // content: '请升级微信',
- // showCancel: false
- // })
- // }
- },
- checkWxLogin: function() {
- return new Promise((resolve, reject) => {
- wx.getSetting({
- success(res) {
- if (!res.authSetting['scope.userInfo']) {
- return reject({
- authSetting: false
- });
- } else {
- wx.getStorage({
- key: 'token',
- success(token) {
- util.check_login_new().then(isLogin=>{
- if (isLogin) {
- // 已登录未过期
- return resolve(false);
- console.log('已登录未过期')
- } else {
- console.log('过期')
- if (token) {
- return resolve(token);
- } else {
- return reject(res);
- }
- }
- })
- },
- fail(res) {
- return reject(res);
- }
- })
- }
- },
- fail(res) {
- return reject(res);
- }
- })
- })
- }
- }
- });
|