抖音b端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

222 řádky
6.3 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: '../../assets/images/logo.png',
  9. phone: '',
  10. pwd: '',
  11. status:'',
  12. showpass: "hidepass",
  13. focus:false,
  14. password: true
  15. },
  16. onLoad() {
  17. Common.getMallIcon()
  18. .then(data => {
  19. // debugge
  20. console.log(data,777)
  21. this.setData({
  22. logo: data.data&&data.data.mallImgUrl ? data.data.mallImgUrl : '../../assets/images/logo.png',
  23. })
  24. })
  25. },
  26. onShow() {
  27. var that = this;
  28. var phone = tt.getStorageSync("phone");
  29. var pwd = tt.getStorageSync("pwd");
  30. that.ttLogin();
  31. if (phone) {
  32. that.setData({
  33. phone: phone
  34. });
  35. }
  36. if (pwd) {
  37. that.setData({
  38. pwd: pwd
  39. });
  40. }
  41. },
  42. //显示具体的密码
  43. showpassword:function(){
  44. console.log(this.data.password);
  45. let that = this;
  46. if (that.data.password){
  47. that.setData({
  48. password: false,
  49. focus:true
  50. })
  51. }else{
  52. that.setData({
  53. password: true,
  54. focus: true
  55. })
  56. }
  57. },
  58. ttLogin(flag){
  59. let that = this;
  60. tt.login({
  61. success: res => {
  62. Common.getSuperOpenId(res.code)
  63. .then(res => {
  64. console.log(res)
  65. if (res.data&& res.data.data&&res.data.data.openId){
  66. app.globalData.superopenId = res.data.data.openId;
  67. }
  68. if (res.data && res.data.data && res.data.data.session_key){
  69. app.globalData.session_key = res.data.data.session_key;
  70. }
  71. if (res.data.code == 200) {
  72. app.globalData.phone = res.data.data.phone;
  73. that.setData({
  74. ifAlBoss: true,
  75. status: "use"
  76. })
  77. if (flag =='fromgetPhoneNumber'){
  78. tt.navigateTo({
  79. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  80. })
  81. }
  82. } else {
  83. if (flag =='fromgetPhoneNumber'){
  84. tt.showToast({
  85. title: res.data.message,
  86. icon: "none",
  87. duration: 2000
  88. })
  89. }
  90. }
  91. }).catch(error => {
  92. console.log(error,"error");
  93. that.setData({
  94. error: error.message
  95. })
  96. })
  97. }
  98. })
  99. },
  100. showpass: function () {
  101. let that = this;
  102. },
  103. forgetPwd: function () {
  104. tt.navigateTo({
  105. url: '/pages/index/forgetpwd/forgetpwd',
  106. })
  107. },
  108. getLoginInfo(e) {
  109. var phoneReg = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/;
  110. let {
  111. phone,
  112. pwd
  113. } = e.detail.value;
  114. if (phoneReg.test(phone)) {
  115. if (pwd != '') {
  116. Common.userLogin(phone, pwd, app.globalData.latitude, app.globalData.longitude)
  117. .then(res => {
  118. console.log(res);
  119. if (res.code == 200) {
  120. HttpBasics.setBUserId(res.data.bUserId);
  121. tt.setStorageSync("phone", phone);
  122. tt.setStorageSync("pwd", pwd);
  123. tt.setStorageSync("bUserId", res.data.bUserId);
  124. app.globalData.bUserId = res.data.bUserId;
  125. tt.setStorage({
  126. key: 'bUserId',
  127. data: res.data.bUserId,
  128. })
  129. tt.login({
  130. success:function(res){
  131. Common.getOpenId(res.code,app.globalData.bUserId)
  132. .then(res => {
  133. console.log(res,888)
  134. app.globalData.openId = res.data.data.openId;
  135. app.globalData.token = res.data.data.token;
  136. HttpBasics.setToken(res.data.data.token);
  137. tt.setStorageSync("openId", res.data.data.openId);
  138. tt.setStorageSync("session_key", res.data.data.session_key);
  139. tt.showToast({
  140. image: './../../assets/images/success.png',
  141. title: '登录成功',
  142. })
  143. tt.switchTab({
  144. url: '/pages/main/main',
  145. success(res) {
  146. console.log(`${res}`);
  147. },
  148. fail(err) {
  149. console.log(err,`switchTab调用失败`);
  150. },
  151. })
  152. })
  153. }
  154. })
  155. } else {
  156. tt.showToast({
  157. image:'./../../assets/images/fail.png',
  158. title: res.message,
  159. icon: "none"
  160. })
  161. }
  162. })
  163. } else {
  164. tt.showToast({
  165. image: './../../assets/images/fail.png',
  166. title: '密码不能为空',
  167. icon: "none",
  168. })
  169. }
  170. } else if(phone=="") {
  171. tt.showToast({
  172. image: './../../assets/images/fail.png',
  173. title: '请输入手机号',
  174. icon: "none"
  175. })
  176. }else{
  177. tt.showToast({
  178. image: './../../assets/images/fail.png',
  179. title: '手机号有误',
  180. icon: "none"
  181. })
  182. }
  183. },
  184. /**
  185. * 获得超级管理员手机号
  186. */
  187. getPhoneNumber: function (e) {
  188. this.ttLogin("fromgetPhoneNumber");
  189. if (app.globalData.superopenId && app.globalData.session_key){
  190. let { encryptedData, iv } = { encryptedData: e.detail.encryptedData, iv: e.detail.iv };
  191. if (encryptedData && iv) {
  192. Common.getUserPhone(encryptedData, iv, app.globalData.superopenId, app.globalData.session_key)
  193. .then(res => {
  194. if (res.data.code == 200 && res.data.data.admin == 1) {
  195. app.globalData.phone = res.data.data.phone;
  196. tt.navigateTo({
  197. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  198. })
  199. }
  200. })
  201. }
  202. }
  203. },
  204. /**
  205. * 用户点击右上角分享
  206. */
  207. onShareAppMessage: function (res) {
  208. let _this = this;
  209. return {
  210. title: '数据塔台',
  211. path: '/pages/main/main',
  212. success: function (res) {
  213. // 转发成功
  214. },
  215. fail: function (res) {
  216. // 转发失败
  217. }
  218. }
  219. },
  220. })