电速宝
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // pages/login/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 状态栏高度
  9. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  10. // 导航栏高度
  11. navBarHeight: wx.getStorageSync('navBarHeight'),
  12. // 导航栏和状态栏高度
  13. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  14. // 胶囊
  15. menu:wx.getStorageSync('menu'),
  16. account:'',
  17. password:'',
  18. passwordtype:true,
  19. checked:false,
  20. shakeClass: '', // 控制晃动动画的类名
  21. Loginswitch:true
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. // 检查是否需要展示隐私协议
  28. wx.getPrivacySetting({
  29. success: res => {
  30. if (res.needAuthorization) {
  31. // 需要用户同意隐私协议,显示授权弹窗
  32. this.setData({
  33. showPrivacy: true
  34. })
  35. }
  36. }
  37. })
  38. },
  39. onpassword(){
  40. console.log(111);
  41. this.setData({
  42. passwordtype:!this.data.passwordtype
  43. })
  44. },
  45. checkboxChange(e) {
  46. let _this = this
  47. console.log('checkbox发生change事件,携带value值为:', e.currentTarget.dataset.value)
  48. wx.requestSubscribeMessage({
  49. tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
  50. success(res) {
  51. console.log(res);
  52. if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') {
  53. // 用户同意订阅
  54. console.log(2222222);
  55. console.log(!e.currentTarget.dataset.value);
  56. _this.setData({
  57. checked:!e.currentTarget.dataset.value
  58. })
  59. }else{
  60. wx.showToast({
  61. title: '您将收不到新工单通知',
  62. icon: 'success',
  63. });
  64. }
  65. },fail: (err) => {
  66. // console.error('请求失败:', err);
  67. console.log(err);
  68. wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
  69. }
  70. })
  71. },
  72. onHandleLogin(){
  73. wx.getPhoneNumber({
  74. success: (res) => {
  75. const encryptedData = res.encryptedData;
  76. const iv = res.iv;
  77. console.log(encryptedData);
  78. console.log(iv);
  79. // 将encryptedData和iv发送给后端,用于解密手机号码
  80. },
  81. fail: (err) => {
  82. console.error('获取手机号码失败', err);
  83. }
  84. });
  85. },
  86. authorizationbtn(){
  87. wx.requestSubscribeMessage({
  88. tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
  89. success(res) {
  90. console.log(res);
  91. if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'] === 'accept') {
  92. // 用户同意订阅
  93. }
  94. }
  95. })
  96. },
  97. bindKeyInput1: function (e) {
  98. this.setData({
  99. account: e.detail.value
  100. })
  101. },
  102. bindKeyInput2: function (e) {
  103. this.setData({
  104. password: e.detail.value
  105. })
  106. },
  107. // 隐私协议同意按钮回调
  108. handleAgreePrivacy() {
  109. this.setData({
  110. showPrivacy: false
  111. })
  112. // 用户同意后,再执行登录流程
  113. },
  114. onstatus(){
  115. if (!this.data.checked) {
  116. return wx.showToast({
  117. title: '请勾选同意',
  118. icon: 'none',
  119. });
  120. }
  121. },
  122. // 获取手机号回调
  123. onGetPhoneNumber(e) {
  124. console.log(e);
  125. let _this = this
  126. if (!this.data.checked) {
  127. return wx.showToast({
  128. title: '请勾选同意',
  129. icon: 'none',
  130. });
  131. }
  132. // wx.requestSubscribeMessage({
  133. // tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
  134. // success(res) {
  135. // console.log(res);
  136. // if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') {
  137. // // 用户同意订阅
  138. // console.log(2222222);
  139. wx.login({
  140. success: ress => {
  141. console.log(ress);
  142. const code = ress.code;
  143. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  144. // 这里的 your_server_url 需要替换成你自己的服务器地址
  145. let obj = {
  146. phonecode:e.detail.code,
  147. code:code
  148. }
  149. api.request(`/SysPartnerLogController/login`, 'post',obj,{ isPublic: true })
  150. .then((data) => {
  151. console.log(data);
  152. if (data.code == 200) {
  153. // 设置数据到本地存储
  154. wx.setStorage({
  155. key: 'token', // 存储的key值
  156. data:data.data.token,
  157. success: function(ress) {
  158. console.log(ress);
  159. wx.reLaunch({
  160. url: '/pages/index/index'
  161. });
  162. wx.showToast({
  163. title: '登录成功',
  164. icon: 'success',
  165. });
  166. }
  167. });
  168. }else{
  169. wx.showToast({
  170. title: data.msg,
  171. icon: 'success',
  172. });
  173. }
  174. })
  175. .catch((err) => {
  176. wx.showToast({
  177. title:'登录失败',
  178. icon: 'none',
  179. });
  180. console.error('请求失败:', err);
  181. });
  182. }
  183. })
  184. // }else{
  185. // wx.showToast({
  186. // title: '您将收不到新工单通知',
  187. // icon: 'success',
  188. // });
  189. // }
  190. // },fail: (err) => {
  191. // // console.error('请求失败:', err);
  192. // console.log(err);
  193. // wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
  194. // }
  195. // })
  196. },
  197. // 处理登录按钮点击
  198. onLogin() {
  199. // 获取本地存储的数据
  200. if (!this.data.checked) {
  201. return wx.showToast({
  202. title: '请勾选同意',
  203. icon: 'none',
  204. });
  205. }
  206. if(this.data.account==''){
  207. return wx.showToast({
  208. title: '请输入手机号码',
  209. icon: 'none',
  210. });
  211. }else if(this.data.account.length!=11) {
  212. return wx.showToast({
  213. title: '请输入正确手机号码',
  214. icon: 'none',
  215. });
  216. }
  217. let _this = this
  218. wx.login({
  219. success: res => {
  220. console.log(res);
  221. const code = res.code;
  222. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  223. // 这里的 your_server_url 需要替换成你自己的服务器地址
  224. let obj = {
  225. phone:_this.data.account,
  226. code:code,
  227. sharecode:_this.data.password
  228. }
  229. api.request(`/SysPartnerLogController/loginphone`, 'post',obj,{ isPublic: true })
  230. .then((data) => {
  231. console.log(data);
  232. if (data.code == 200) {
  233. // 设置数据到本地存储
  234. wx.setStorage({
  235. key: 'token', // 存储的key值
  236. data:data.data.token,
  237. success: function(ress) {
  238. console.log(ress);
  239. wx.reLaunch({
  240. url: '/pages/index/index'
  241. });
  242. wx.showToast({
  243. title: '登录成功',
  244. icon: 'success',
  245. });
  246. }
  247. });
  248. }else{
  249. wx.showToast({
  250. title: data.msg,
  251. icon: 'success',
  252. });
  253. }
  254. })
  255. .catch((err) => {
  256. wx.showToast({
  257. title:err.msg+',请使用手机号一键登录',
  258. icon: 'none',
  259. });
  260. console.error('请求失败:', err);
  261. });
  262. }
  263. })
  264. },
  265. onprivacy(e){
  266. console.log(e.target.dataset.name);
  267. wx.navigateTo({
  268. url: `/pages/privacy/index?name=${e.target.dataset.name}`,
  269. })
  270. },
  271. // 切换登录模式
  272. onswitch(e){
  273. console.log(e);
  274. // if (!e.target.dataset.value) {
  275. // return wx.showToast({
  276. // title: '待开发',
  277. // icon: 'none',
  278. // });
  279. // }
  280. this.setData({
  281. Loginswitch:e.target.dataset.value
  282. })
  283. },
  284. /**
  285. * 生命周期函数--监听页面初次渲染完成
  286. */
  287. onReady() {
  288. },
  289. /**
  290. * 生命周期函数--监听页面显示
  291. */
  292. onShow() {
  293. },
  294. /**
  295. * 生命周期函数--监听页面隐藏
  296. */
  297. onHide() {
  298. },
  299. /**
  300. * 生命周期函数--监听页面卸载
  301. */
  302. onUnload() {
  303. },
  304. /**
  305. * 页面相关事件处理函数--监听用户下拉动作
  306. */
  307. onPullDownRefresh() {
  308. },
  309. /**
  310. * 页面上拉触底事件的处理函数
  311. */
  312. onReachBottom() {
  313. },
  314. /**
  315. * 用户点击右上角分享
  316. */
  317. onShareAppMessage() {
  318. }
  319. })