运维小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 8.7KB

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