电速宝
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. if (e.currentTarget.dataset.value) {
  49. return
  50. }
  51. wx.requestSubscribeMessage({
  52. tmplIds: ['t46217wOQ7HBvw0MfP78Zo8FuwYTKBESaGYIpaXccFw','lLN0xmyLgBSnvveLAOhHiEHvHUi286idSuv-kO61TMI'],
  53. success(res) {
  54. console.log(res);
  55. if(res['t46217wOQ7HBvw0MfP78Zo8FuwYTKBESaGYIpaXccFw'] === 'accept') {
  56. // 用户同意订阅
  57. console.log(2222222);
  58. console.log(!e.currentTarget.dataset.value);
  59. _this.setData({
  60. checked:!e.currentTarget.dataset.value
  61. })
  62. }else{
  63. wx.showToast({
  64. title: '您将收不到新工单通知',
  65. icon: 'success',
  66. });
  67. }
  68. },fail: (err) => {
  69. // console.error('请求失败:', err);
  70. console.log(err);
  71. wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
  72. }
  73. })
  74. },
  75. onHandleLogin(){
  76. wx.getPhoneNumber({
  77. success: (res) => {
  78. const encryptedData = res.encryptedData;
  79. const iv = res.iv;
  80. console.log(encryptedData);
  81. console.log(iv);
  82. // 将encryptedData和iv发送给后端,用于解密手机号码
  83. },
  84. fail: (err) => {
  85. console.error('获取手机号码失败', err);
  86. }
  87. });
  88. },
  89. bindKeyInput1: function (e) {
  90. this.setData({
  91. account: e.detail.value
  92. })
  93. },
  94. bindKeyInput2: function (e) {
  95. this.setData({
  96. password: e.detail.value
  97. })
  98. },
  99. // 隐私协议同意按钮回调
  100. handleAgreePrivacy() {
  101. this.setData({
  102. showPrivacy: false
  103. })
  104. // 用户同意后,再执行登录流程
  105. },
  106. // 获取手机号回调
  107. onGetPhoneNumber(e) {
  108. console.log(e);
  109. let _this = this
  110. if (!this.data.checked) {
  111. return wx.showToast({
  112. title: '请勾选同意',
  113. icon: 'none',
  114. });
  115. }
  116. wx.login({
  117. success: ress => {
  118. console.log(ress);
  119. const code = ress.code;
  120. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  121. // 这里的 your_server_url 需要替换成你自己的服务器地址
  122. let obj = {
  123. // phonecode:e.detail.code,
  124. phonecode:this.data.account,
  125. code:code,
  126. password:this.data.password
  127. }
  128. api.request(`/sysoperation/login`, 'post',obj,{ isPublic: true })
  129. .then((data) => {
  130. console.log(data);
  131. if (data.code == 200) {
  132. // 设置数据到本地存储
  133. wx.setStorage({
  134. key: 'token', // 存储的key值
  135. data:data.data.token,
  136. success: function(ress) {
  137. console.log(ress);
  138. wx.reLaunch({
  139. url: '/pages/index/index'
  140. });
  141. wx.showToast({
  142. title: '登录成功',
  143. icon: 'success',
  144. });
  145. }
  146. });
  147. }else{
  148. wx.showToast({
  149. title: data.msg,
  150. icon: 'success',
  151. });
  152. }
  153. })
  154. .catch((err) => {
  155. wx.showToast({
  156. title:'登录失败',
  157. icon: 'none',
  158. });
  159. console.error('请求失败:', err);
  160. });
  161. }
  162. })
  163. },
  164. promptcheck(){
  165. return wx.showToast({
  166. title: '请勾选同意',
  167. icon: 'none',
  168. });
  169. },
  170. // 处理登录按钮点击
  171. onLogin() {
  172. // 获取本地存储的数据
  173. if (!this.data.checked) {
  174. return wx.showToast({
  175. title: '请勾选同意',
  176. icon: 'none',
  177. });
  178. }
  179. if(this.data.account==''){
  180. return wx.showToast({
  181. title: '请输入手机号码',
  182. icon: 'none',
  183. });
  184. }else if(this.data.account.length!=11) {
  185. return wx.showToast({
  186. title: '请输入正确手机号码',
  187. icon: 'none',
  188. });
  189. }
  190. let _this = this
  191. wx.login({
  192. success: res => {
  193. console.log(res);
  194. const code = res.code;
  195. // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
  196. // 这里的 your_server_url 需要替换成你自己的服务器地址
  197. let obj = {
  198. phone:_this.data.account,
  199. code:code,
  200. sharecode:_this.data.password
  201. }
  202. api.request(`/SysPartnerLogController/loginphone`, 'post',obj,{ isPublic: true })
  203. .then((data) => {
  204. console.log(data);
  205. if (data.code == 200) {
  206. // 设置数据到本地存储
  207. wx.setStorage({
  208. key: 'token', // 存储的key值
  209. data:data.data.token,
  210. success: function(ress) {
  211. console.log(ress);
  212. wx.reLaunch({
  213. url: '/pages/index/index'
  214. });
  215. wx.showToast({
  216. title: '登录成功',
  217. icon: 'success',
  218. });
  219. }
  220. });
  221. }else{
  222. wx.showToast({
  223. title: data.msg,
  224. icon: 'success',
  225. });
  226. }
  227. })
  228. .catch((err) => {
  229. wx.showToast({
  230. title:err.msg+',请使用手机号一键登录',
  231. icon: 'none',
  232. });
  233. console.error('请求失败:', err);
  234. });
  235. }
  236. })
  237. },
  238. onprivacy(e){
  239. console.log(e.target.dataset.name);
  240. wx.navigateTo({
  241. url: `/package-user/pages/privacy/index?name=${e.target.dataset.name}`,
  242. })
  243. },
  244. // 切换登录模式
  245. onswitch(e){
  246. console.log(e);
  247. // if (!e.target.dataset.value) {
  248. // return wx.showToast({
  249. // title: '待开发',
  250. // icon: 'none',
  251. // });
  252. // }
  253. this.setData({
  254. Loginswitch:e.target.dataset.value
  255. })
  256. },
  257. onregister(){
  258. wx.navigateTo({
  259. url: `/package-user/pages/register/index`,
  260. })
  261. },
  262. /**
  263. * 生命周期函数--监听页面初次渲染完成
  264. */
  265. onReady() {
  266. },
  267. /**
  268. * 生命周期函数--监听页面显示
  269. */
  270. onShow() {
  271. },
  272. /**
  273. * 生命周期函数--监听页面隐藏
  274. */
  275. onHide() {
  276. },
  277. /**
  278. * 生命周期函数--监听页面卸载
  279. */
  280. onUnload() {
  281. },
  282. /**
  283. * 页面相关事件处理函数--监听用户下拉动作
  284. */
  285. onPullDownRefresh() {
  286. },
  287. /**
  288. * 页面上拉触底事件的处理函数
  289. */
  290. onReachBottom() {
  291. },
  292. /**
  293. * 用户点击右上角分享
  294. */
  295. onShareAppMessage() {
  296. }
  297. })