index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. var util = require('../../utils/util.js');
  2. var location = require('../../utils/Location.js');
  3. var app = getApp();
  4. Component({
  5. properties: {
  6. needAuth: {
  7. type: Boolean,
  8. value: false
  9. },
  10. needPosition: {
  11. type: Boolean,
  12. value: true
  13. },
  14. navBackUrl: {
  15. type: String,
  16. value: '',
  17. observer: function (t) {
  18. if (t) app.globalData.navBackUrl = t;
  19. }
  20. }
  21. },
  22. attached: function () {
  23. this.setData({
  24. skin: getApp().globalData.skin,
  25. })
  26. this.getBg();
  27. },
  28. data: {
  29. nickname:'',
  30. avatarUrl:'../../images/sctx.png',
  31. btnLoading: false,
  32. canIUse: wx.canIUse('button.open-type.getUserInfo')
  33. },
  34. methods: {
  35. agree:function(){
  36. console.log("用户同意隐私授权, 接下来可以调用隐私协议中声明的隐私接口")
  37. },
  38. disagree:function(){
  39. console.log("用户拒绝隐私授权, 未同意过的隐私协议中的接口将不能调用")
  40. // this.triggerEvent("cancel");
  41. wx.showToast({
  42. title: '需同意后才可以继续使用千古秀鲜花铺材小程序',
  43. duration: 2000,
  44. icon:"none"
  45. })
  46. },
  47. onChooseAvatar(e) {
  48. console.log(e.detail,'0000000000')
  49. this.setData({
  50. avatarUrl:e.detail.avatarUrl
  51. })
  52. },
  53. handleAgreePrivacyAuthorization() {
  54. console.log("同意了")
  55. },
  56. getBg: function () {
  57. let that = this;
  58. app.util.request({
  59. 'url': 'entry/wxapp/index',
  60. 'data': {
  61. controller: 'index.get_newauth_bg'
  62. },
  63. dataType: 'json',
  64. success: function (res) {
  65. that.setData({ loaded: true })
  66. if (res.data.code == 0) {
  67. let { newauth_bg_image, newauth_confirm_image, newauth_cancel_image } = res.data.data;
  68. that.setData({ newauth_bg_image, newauth_confirm_image, newauth_cancel_image })
  69. }
  70. }
  71. })
  72. },
  73. close: function () {
  74. this.triggerEvent("cancel");
  75. },
  76. bindGetUserInfo: function (t) {
  77. var that = this;
  78. if (!this.data.btnLoading) {
  79. var n = t.detail;
  80. if (this.setData({ btnLoading: true }), "getUserInfo:ok" === n.errMsg) {
  81. util.login_prosime(that.data.needPosition).then(function () {
  82. console.log("授权成功")
  83. that.setData({ btnLoading: false });
  84. wx.showToast({
  85. title: '登录成功',
  86. icon: 'success',
  87. duration: 2000
  88. })
  89. that.triggerEvent("authSuccess");
  90. app.globalData.changedCommunity = true;
  91. //检查获取位置权限
  92. that.data.needPosition && location.getGps();
  93. }).catch(function () {
  94. that.triggerEvent("cancel");
  95. console.log('授权失败');
  96. })
  97. } else {
  98. wx.showToast({
  99. title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
  100. icon: "none"
  101. });
  102. this.triggerEvent("cancel");
  103. this.setData({ btnLoading: false });
  104. }
  105. }
  106. },
  107. getProfile: function() {
  108. var that = this;
  109. console.log(this.data.nickname,'9999')
  110. //非空验证
  111. if(this.data.avatarUrl=='../../images/sctx.png'){
  112. wx.showToast({
  113. title: "请上传头像",
  114. icon: "none"
  115. });
  116. return false;
  117. }
  118. if(this.data.nickname==''){
  119. wx.showToast({
  120. title: "",
  121. icon: "none"
  122. });
  123. return false;
  124. }
  125. wx.uploadFile({
  126. url: app.util.url('entry/wxapp/index', {'m':'lionfish_comshop','controller':'goods.doPageUpload'}),
  127. filePath: that.data.avatarUrl,
  128. name: 'upfile',
  129. formData: {
  130. 'name':that.data.avatarUrl
  131. },
  132. header: {
  133. 'content-type': 'multipart/form-data'
  134. },
  135. success: function (res) {
  136. var data = JSON.parse(res.data);
  137. console.log(data.image_o,'000000000000000000000')
  138. that.setData({
  139. avatarUrl:data.image_o
  140. })
  141. }
  142. })
  143. console.log(wx.canIUse("getUserProfile"));
  144. if (!that.data.btnLoading) {
  145. // if(wx.canIUse("getUserProfile")) {
  146. wx.getUserProfile({
  147. desc: "获取你的昵称、头像、地区及性别",
  148. success: function (msg) {
  149. var userInfo = msg.userInfo
  150. userInfo['nickName']=that.data.nickname
  151. userInfo['avatarUrl']=that.data.avatarUrl
  152. console.log( userInfo,'898989')
  153. wx.setStorage({
  154. key: "userInfo",
  155. data: userInfo
  156. })
  157. that.setData({ btnLoading: true });
  158. util.login_prosime(that.data.needPosition, userInfo).then( res => {
  159. console.log("授权成功")
  160. that.setData({ btnLoading: false });
  161. wx.showToast({
  162. title: '登录成功',
  163. icon: 'success',
  164. duration: 2000
  165. })
  166. that.triggerEvent("authSuccess", res);
  167. app.globalData.changedCommunity = true;
  168. //检查获取位置权限
  169. that.data.needPosition && location.getGps();
  170. }).catch(function () {
  171. that.triggerEvent("cancel");
  172. console.log('授权失败');
  173. })
  174. },
  175. fail: ()=>{
  176. wx.showToast({
  177. title: "授权失败,为了完整体验,获取更多优惠活动,需要您的授权。",
  178. icon: "none"
  179. });
  180. that.triggerEvent("cancel");
  181. that.setData({ btnLoading: false });
  182. }
  183. })
  184. }
  185. // } else {
  186. // wx.showModal({
  187. // title: '提示',
  188. // content: '请升级微信',
  189. // showCancel: false
  190. // })
  191. // }
  192. },
  193. checkWxLogin: function() {
  194. return new Promise((resolve, reject) => {
  195. wx.getSetting({
  196. success(res) {
  197. if (!res.authSetting['scope.userInfo']) {
  198. return reject({
  199. authSetting: false
  200. });
  201. } else {
  202. wx.getStorage({
  203. key: 'token',
  204. success(token) {
  205. util.check_login_new().then(isLogin=>{
  206. if (isLogin) {
  207. // 已登录未过期
  208. return resolve(false);
  209. console.log('已登录未过期')
  210. } else {
  211. console.log('过期')
  212. if (token) {
  213. return resolve(token);
  214. } else {
  215. return reject(res);
  216. }
  217. }
  218. })
  219. },
  220. fail(res) {
  221. return reject(res);
  222. }
  223. })
  224. }
  225. },
  226. fail(res) {
  227. return reject(res);
  228. }
  229. })
  230. })
  231. }
  232. }
  233. });