Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

339 строки
9.2 KiB

  1. const config = require('../../config/config.js')
  2. const app = getApp()
  3. const Common = require('../../common/common.js')
  4. const Http = require('../../utils/http.js')
  5. const HttpBasics = require('../../utils/HttpBasics.js')
  6. Page({
  7. data: {
  8. logo: '../../static/images/logo.png',
  9. phone: '',
  10. pwd: '',
  11. status: '',
  12. showpass: "hidepass",
  13. focus: false,
  14. password: 'password',
  15. showPrivacy: false
  16. },
  17. onLoad() {
  18. Common.getMallIcon()
  19. .then(data => {
  20. // debugge
  21. this.setData({
  22. logo: data.data && data.data.mallImgUrl ? data.data.mallImgUrl : '../../static/images/logo.png'
  23. })
  24. })
  25. this.getPrivacySetting()
  26. },
  27. onShow() {
  28. var that = this;
  29. var phone = wx.getStorageSync("phone");
  30. var pwd = wx.getStorageSync("pwd");
  31. that.wxLogin();
  32. if (phone) {
  33. that.setData({
  34. phone: phone
  35. });
  36. }
  37. if (pwd) {
  38. that.setData({
  39. pwd: pwd
  40. });
  41. }
  42. },
  43. //显示具体的密码
  44. showpassword: function () {
  45. console.log(this.data.password);
  46. let that = this;
  47. if (that.data.password == 'password') {
  48. that.setData({
  49. password: 'text',
  50. focus: true
  51. })
  52. } else {
  53. that.setData({
  54. password: 'password',
  55. focus: true
  56. })
  57. }
  58. },
  59. wxLogin(flag) {
  60. let that = this;
  61. wx.login({
  62. success: res => {
  63. Common.getSuperOpenId(res.code)
  64. .then(res => {
  65. console.log(res)
  66. if (res.data && res.data.data && res.data.data.openId) {
  67. app.globalData.superopenId = res.data.data.openId;
  68. }
  69. if (res.data && res.data.data && res.data.data.session_key) {
  70. app.globalData.session_key = res.data.data.session_key;
  71. }
  72. if (res.data.code == 200) {
  73. app.globalData.phone = res.data.data.phone;
  74. that.setData({
  75. // ifAlBoss: true,
  76. status: "use"
  77. })
  78. if (flag == 'fromgetPhoneNumber') {
  79. wx.navigateTo({
  80. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  81. })
  82. }
  83. } else {
  84. if (flag == 'fromgetPhoneNumber') {
  85. wx.showToast({
  86. title: res.data.message,
  87. icon: "none",
  88. duration: 2000
  89. })
  90. }
  91. }
  92. })
  93. .catch(error => {
  94. that.setData({
  95. error: error.message
  96. })
  97. })
  98. }
  99. })
  100. },
  101. showpass: function () {
  102. let that = this;
  103. },
  104. phoneInput(e) {
  105. this.setData({
  106. phone: e.detail.value
  107. })
  108. },
  109. pwdInput(e) {
  110. this.setData({
  111. pwd: e.detail.value
  112. })
  113. },
  114. forgetPwd() {
  115. wx.navigateTo({
  116. url: '/pages/index/forgetpwd/forgetpwd',
  117. })
  118. },
  119. reStore() {
  120. const phone = this.data.phone
  121. const pwd = this.data.pwd
  122. if (!phone || !pwd) {
  123. wx.showToast({
  124. title: '请输手机号或密码!',
  125. icon: 'none'
  126. })
  127. return
  128. }
  129. const data = {
  130. detail: {
  131. value: {
  132. phone: phone,
  133. pwd: pwd
  134. }
  135. }
  136. }
  137. this.getLoginInfo(data, true)
  138. },
  139. getLoginInfo(e, flag) {
  140. var phoneReg = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/;
  141. let {
  142. phone,
  143. pwd
  144. } = e.detail.value;
  145. if (phoneReg.test(phone)) {
  146. if (pwd != '') {
  147. Common.userLogin(phone, pwd, app.globalData.latitude, app.globalData.longitude)
  148. .then(res => {
  149. console.log(res, 'login');
  150. if (res.code == 200) {
  151. // console.log(res,7777777)
  152. HttpBasics.setBUserId(res.data.bUserId);
  153. wx.setStorageSync("phone", phone);
  154. wx.setStorageSync("pwd", pwd);
  155. wx.setStorageSync("bUserId", res.data.bUserId);
  156. app.globalData.bUserId = res.data.bUserId;
  157. wx.setStorage({
  158. key: 'bUserId',
  159. data: res.data.bUserId,
  160. })
  161. wx.login({
  162. success: function (res) {
  163. Common.getOpenId(res.code, app.globalData.bUserId, !flag)
  164. .then(res => {
  165. console.log(res, 'openId');
  166. app.globalData.openId = res.data.data.openId;
  167. app.globalData.token = res.data.data.token;
  168. HttpBasics.setToken(res.data.data.token);
  169. wx.setStorageSync("openId", res.data.data.openId);
  170. wx.setStorageSync("session_key", res.data.data.session_key);
  171. wx.showToast({
  172. image: './../../static/images/success.png',
  173. title: '登录成功',
  174. })
  175. if (!flag) {
  176. wx.switchTab({
  177. url: '/pages/main/main',
  178. })
  179. } else {
  180. wx.navigateTo({
  181. url: `/pages/getuserinfo/index?path=login`,
  182. })
  183. }
  184. })
  185. .catch(err => {
  186. console.log(err, 'err');
  187. wx.showToast({
  188. title: err.data.message,
  189. icon: 'none',
  190. })
  191. })
  192. }
  193. })
  194. } else {
  195. wx.showToast({
  196. image: './../../static/images/fail.png',
  197. title: res.message,
  198. })
  199. }
  200. })
  201. } else {
  202. wx.showToast({
  203. image: './../../static/images/fail.png',
  204. title: '密码不能为空',
  205. })
  206. }
  207. } else {
  208. wx.showToast({
  209. image: './../../static/images/fail.png',
  210. title: '手机号有误',
  211. })
  212. }
  213. },
  214. /**
  215. * 获得超级管理员手机号
  216. */
  217. getPhoneNumber: function (e) {
  218. console.log(e)
  219. // this.wxLogin("fromgetPhoneNumber");
  220. if (app.globalData.superopenId && app.globalData.session_key) {
  221. let { encryptedData, iv } = { encryptedData: e.detail.encryptedData, iv: e.detail.iv };
  222. if (encryptedData && iv) {
  223. Common.getUserPhone(encryptedData, iv, app.globalData.superopenId, app.globalData.session_key)
  224. .then(res => {
  225. if (res.data.code == 200 && res.data.data.admin == 1) {
  226. app.globalData.token = res.data.data.token
  227. app.globalData.phone = res.data.data.phone;
  228. wx.navigateTo({
  229. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  230. })
  231. } else {
  232. wx.showToast({
  233. title: res.data.message,
  234. icon: "none",
  235. duration: 2000
  236. })
  237. }
  238. }).catch(error => {
  239. console.log(error)
  240. wx.showToast({
  241. title: error.message,
  242. icon: "none",
  243. duration: 2000
  244. })
  245. })
  246. }
  247. }
  248. },
  249. clickPrivacy(e) {
  250. },
  251. closePrivacy() {
  252. wx.exitMiniProgram()
  253. },
  254. getPrivacySetting() {
  255. const canIUsePrivacy = wx.canIUse('getPrivacySetting')
  256. console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
  257. if (canIUsePrivacy) {
  258. wx.getPrivacySetting({
  259. success: res => {
  260. console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  261. if (res.needAuthorization) {
  262. // 需要弹出隐私协议
  263. this.setData({
  264. showPrivacy: true
  265. })
  266. } else {
  267. // this.setData({
  268. // showPrivacy: true
  269. // })
  270. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  271. // wx.getUserProfile()
  272. // wx.chooseMedia()
  273. // wx.getClipboardData()
  274. // wx.startRecord()
  275. // this.setData({
  276. // showPrivacy: true
  277. // })
  278. }
  279. },
  280. fail: () => { },
  281. complete: () => { }
  282. })
  283. }
  284. },
  285. handleAgreePrivacyAuthorization() {
  286. console.log('Privacy Agreed!');
  287. this.setData({
  288. showPrivacy: false
  289. })
  290. // 用户同意隐私协议事件回调
  291. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  292. // wx.getUserProfile()
  293. // wx.chooseMedia()
  294. // wx.getClipboardData()
  295. // wx.startRecord()
  296. },
  297. handleOpenPrivacyContract() {
  298. // 打开隐私协议页面
  299. wx.openPrivacyContract({
  300. success: () => {
  301. // this.setData({
  302. // showPrivacy: false
  303. // })
  304. }, // 打开成功
  305. fail: () => { }, // 打开失败
  306. complete: () => { }
  307. })
  308. },
  309. /**
  310. * 用户点击右上角分享
  311. */
  312. onShareAppMessage: function (res) {
  313. let _this = this;
  314. return {
  315. title: '商管操作台',
  316. path: 'pages/index/index',
  317. success: function (res) {
  318. // 转发成功
  319. },
  320. fail: function (res) {
  321. // 转发失败
  322. }
  323. }
  324. },
  325. })