电速宝
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. // 获取手机号回调
  115. onGetPhoneNumber(e) {
  116. console.log(e);
  117. let _this = this
  118. if (!this.data.checked) {
  119. return wx.showToast({
  120. title: '请勾选同意',
  121. icon: 'none',
  122. });
  123. }
  124. // wx.requestSubscribeMessage({
  125. // tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
  126. // success(res) {
  127. // console.log(res);
  128. // if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') {
  129. // // 用户同意订阅
  130. // console.log(2222222);
  131. wx.login({
  132. success: ress => {
  133. console.log(ress);
  134. const code = ress.code;
  135. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  136. // 这里的 your_server_url 需要替换成你自己的服务器地址
  137. let obj = {
  138. phonecode:e.detail.code,
  139. code:code
  140. }
  141. api.request(`/sysoperation/login`, 'post',obj,{ isPublic: true })
  142. .then((data) => {
  143. console.log(data);
  144. if (data.code == 200) {
  145. // 设置数据到本地存储
  146. wx.setStorage({
  147. key: 'token', // 存储的key值
  148. data:data.data.token,
  149. success: function(ress) {
  150. console.log(ress);
  151. wx.reLaunch({
  152. url: '/pages/index/index'
  153. });
  154. wx.showToast({
  155. title: '登录成功',
  156. icon: 'success',
  157. });
  158. }
  159. });
  160. }else{
  161. wx.showToast({
  162. title: data.msg,
  163. icon: 'success',
  164. });
  165. }
  166. })
  167. .catch((err) => {
  168. wx.showToast({
  169. title:'登录失败',
  170. icon: 'none',
  171. });
  172. console.error('请求失败:', err);
  173. });
  174. }
  175. })
  176. // }else{
  177. // wx.showToast({
  178. // title: '您将收不到新工单通知',
  179. // icon: 'success',
  180. // });
  181. // }
  182. // },fail: (err) => {
  183. // // console.error('请求失败:', err);
  184. // console.log(err);
  185. // wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
  186. // }
  187. // })
  188. },
  189. promptcheck(){
  190. return wx.showToast({
  191. title: '请勾选同意',
  192. icon: 'none',
  193. });
  194. },
  195. // 处理登录按钮点击
  196. onLogin() {
  197. // 获取本地存储的数据
  198. if (!this.data.checked) {
  199. return wx.showToast({
  200. title: '请勾选同意',
  201. icon: 'none',
  202. });
  203. }
  204. if(this.data.account==''){
  205. return wx.showToast({
  206. title: '请输入手机号码',
  207. icon: 'none',
  208. });
  209. }else if(this.data.account.length!=11) {
  210. return wx.showToast({
  211. title: '请输入正确手机号码',
  212. icon: 'none',
  213. });
  214. }
  215. let _this = this
  216. wx.login({
  217. success: res => {
  218. console.log(res);
  219. const code = res.code;
  220. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  221. // 这里的 your_server_url 需要替换成你自己的服务器地址
  222. let obj = {
  223. phone:_this.data.account,
  224. code:code,
  225. sharecode:_this.data.password
  226. }
  227. api.request(`/SysPartnerLogController/loginphone`, 'post',obj,{ isPublic: true })
  228. .then((data) => {
  229. console.log(data);
  230. if (data.code == 200) {
  231. // 设置数据到本地存储
  232. wx.setStorage({
  233. key: 'token', // 存储的key值
  234. data:data.data.token,
  235. success: function(ress) {
  236. console.log(ress);
  237. wx.reLaunch({
  238. url: '/pages/index/index'
  239. });
  240. wx.showToast({
  241. title: '登录成功',
  242. icon: 'success',
  243. });
  244. }
  245. });
  246. }else{
  247. wx.showToast({
  248. title: data.msg,
  249. icon: 'success',
  250. });
  251. }
  252. })
  253. .catch((err) => {
  254. wx.showToast({
  255. title:err.msg+',请使用手机号一键登录',
  256. icon: 'none',
  257. });
  258. console.error('请求失败:', err);
  259. });
  260. }
  261. })
  262. },
  263. onprivacy(e){
  264. console.log(e.target.dataset.name);
  265. wx.navigateTo({
  266. url: `/pages/privacy/index?name=${e.target.dataset.name}`,
  267. })
  268. },
  269. // 切换登录模式
  270. onswitch(e){
  271. console.log(e);
  272. // if (!e.target.dataset.value) {
  273. // return wx.showToast({
  274. // title: '待开发',
  275. // icon: 'none',
  276. // });
  277. // }
  278. this.setData({
  279. Loginswitch:e.target.dataset.value
  280. })
  281. },
  282. /**
  283. * 生命周期函数--监听页面初次渲染完成
  284. */
  285. onReady() {
  286. },
  287. /**
  288. * 生命周期函数--监听页面显示
  289. */
  290. onShow() {
  291. },
  292. /**
  293. * 生命周期函数--监听页面隐藏
  294. */
  295. onHide() {
  296. },
  297. /**
  298. * 生命周期函数--监听页面卸载
  299. */
  300. onUnload() {
  301. },
  302. /**
  303. * 页面相关事件处理函数--监听用户下拉动作
  304. */
  305. onPullDownRefresh() {
  306. },
  307. /**
  308. * 页面上拉触底事件的处理函数
  309. */
  310. onReachBottom() {
  311. },
  312. /**
  313. * 用户点击右上角分享
  314. */
  315. onShareAppMessage() {
  316. }
  317. })