index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="container-login" :style="appThemeStyle">
  3. <!-- 表单 -->
  4. <view class="submit-form">
  5. <!-- 页面头部 -->
  6. <view class="header">
  7. <view class="title">
  8. <text>KDBOSS-管理端</text>
  9. </view>
  10. <view class="sub-title">
  11. <text>请输入管理员账号</text>
  12. </view>
  13. </view>
  14. <!-- 账户 -->
  15. <view class="form-item">
  16. <input class="form-item--input" type="text" v-model="loginForm.account" placeholder="账户" />
  17. </view>
  18. <!-- 密码 -->
  19. <view class="form-item">
  20. <input class="form-item--input" type="text" v-model="loginForm.pwd" placeholder="密码" />
  21. </view>
  22. <!-- 图形验证码 -->
  23. <view class="form-item">
  24. <input class="form-item--input" type="text" v-model="loginForm.code" maxlength="6" placeholder="请输入图形验证码" />
  25. <view class="form-item--parts">
  26. <view class="captcha" @click="getCode()">
  27. <img class="image" :src="codeUrl"></img>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 确认绑定 -->
  33. <view class="submit-button" @click="handleSubmit()">
  34. <text>登 录</text>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import store from '@/store'
  40. import * as UserApi from '@/api/user'
  41. import * as CaptchaApi from '@/api/captcha'
  42. import * as Verify from '@/utils/verify'
  43. import * as AppApi from '@/api/app'
  44. import storage from '@/utils/storage'
  45. import SelectRegion from '@/components/select-region/select-region'
  46. // 倒计时时长(秒)
  47. const times = 60
  48. // 表单验证场景
  49. const GET_CAPTCHA = 10
  50. const FORM_SUBMIT = 20
  51. export default {
  52. data() {
  53. return {
  54. // 正在加载
  55. isLoading: false,
  56. // 图形验证码信息
  57. captcha: {},
  58. // 短信验证码发送状态
  59. smsState: false,
  60. // 倒计时
  61. times,
  62. // 手机号
  63. agentstel: '',
  64. agentsname: '',
  65. agentsadress: '',
  66. address: '',
  67. // 图形验证码
  68. captchaCode: '',
  69. // 短信验证码
  70. smsCode: '',
  71. wx_userid: storage.get('wx_userid'),
  72. wx_openid: storage.get('wx_openid'),
  73. codeUrl: '',
  74. loginForm: {
  75. account: '',
  76. pwd: '',
  77. code: '',
  78. uuid: ''
  79. }
  80. }
  81. },
  82. components: {
  83. SelectRegion
  84. },
  85. /**
  86. * 生命周期函数--监听页面加载
  87. */
  88. created() {
  89. // 获取图形验证码
  90. this.getCode()
  91. },
  92. methods: {
  93. async getCode() {
  94. const app = this
  95. app.regCodeLoading = true
  96. const uuid = app.getUUID()
  97. app.loginForm.uuid = uuid
  98. // 图形验证码
  99. app.codeUrl = 'https://api.hninpop.com/api/sys/getloginvifcode?uuid=' + uuid
  100. },
  101. getUUID() {
  102. var s = []
  103. var hexDigits = '0123456789abcdef'
  104. for (var i = 0; i < 36; i++) {
  105. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  106. }
  107. s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
  108. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
  109. s[8] = s[13] = s[18] = s[23] = '-'
  110. var uuid = s.join('')
  111. return uuid
  112. },
  113. // 获取图形验证码
  114. getCaptcha() {
  115. const app = this
  116. CaptchaApi.image().then((result) => (app.captcha = result.data))
  117. },
  118. // 点击发送短信验证码
  119. handelSmsCaptcha() {
  120. const app = this
  121. if (!app.isLoading && !app.smsState && app.formValidation(GET_CAPTCHA)) {
  122. app.sendSmsCaptcha()
  123. }
  124. },
  125. // 表单验证
  126. formValidation(scene = GET_CAPTCHA) {
  127. const app = this
  128. // 验证获取短信验证码
  129. if (scene === GET_CAPTCHA) {
  130. if (!app.validteMobile(app.agentstel)) {
  131. return false
  132. }
  133. }
  134. // 验证表单提交
  135. if (scene === FORM_SUBMIT) {
  136. if (!app.validteMobile(app.agentstel) || !app.validteSmsCode(app.smsCode)) {
  137. return false
  138. }
  139. }
  140. return true
  141. },
  142. // 验证手机号
  143. validteMobile(str) {
  144. if (Verify.isEmpty(str)) {
  145. this.$toast('请先输入手机号')
  146. return false
  147. }
  148. if (!Verify.isMobile(str)) {
  149. this.$toast('请输入正确格式的手机号')
  150. return false
  151. }
  152. return true
  153. },
  154. // 验证图形验证码
  155. validteCaptchaCode(str) {
  156. if (Verify.isEmpty(str)) {
  157. this.$toast('请先输入图形验证码')
  158. return false
  159. }
  160. return true
  161. },
  162. // 验证短信验证码
  163. validteSmsCode(str) {
  164. if (Verify.isEmpty(str)) {
  165. this.$toast('请先输入短信验证码')
  166. return false
  167. }
  168. return true
  169. },
  170. // 请求发送短信验证码接口
  171. sendSmsCaptcha() {
  172. const app = this
  173. app.isLoading = true
  174. AppApi.getSmsCode({mobile: app.agentstel})
  175. .then((result) => {
  176. // 显示发送成功
  177. app.$toast('发送成功')
  178. // 执行定时器
  179. app.timer()
  180. })
  181. .finally(() => {
  182. app.isLoading = false
  183. })
  184. },
  185. // 执行定时器
  186. timer() {
  187. const app = this
  188. app.smsState = true
  189. const inter = setInterval(() => {
  190. app.times = app.times - 1
  191. if (app.times <= 0) {
  192. app.smsState = false
  193. app.times = times
  194. clearInterval(inter)
  195. }
  196. }, 1000)
  197. },
  198. // 点击提交
  199. handleSubmit() {
  200. const app = this
  201. AppApi.login(app.loginForm)
  202. .then((result) => {
  203. // 显示操作成功
  204. app.$toast('登录成功,正在跳转')
  205. // 登录成功存储企业信息
  206. storage.set('txm_token', '11111')
  207. setTimeout(() => {
  208. this.$navTo('pages/tiaoxingma/index')
  209. // 登录成功 数据清空
  210. app.loginForm.account = ''
  211. app.loginForm.pwd = ''
  212. app.loginForm.code = ''
  213. }, 1000)
  214. })
  215. .finally(() => {
  216. })
  217. },
  218. // 确认提交事件
  219. onSubmitEvent() {
  220. const app = this
  221. if (Verify.isEmpty(app.address)) {
  222. this.$toast('请选择地区')
  223. return false
  224. }
  225. if (Verify.isEmpty(app.agentsname)) {
  226. this.$toast('请填写商户名称')
  227. return false
  228. }
  229. app.isLoading = true
  230. let platform = {
  231. agentscustomerid: storage.get('wx_userid'),
  232. agentsname: app.agentsname,
  233. agentsadress: app.agentsadress,
  234. agentstel: app.agentstel,
  235. agentsprovince: app.address[0].label,
  236. agentscity: app.address[1].label,
  237. agentsarea: app.address[2].label,
  238. smscode: app.smsCode
  239. }
  240. AppApi.companyLogin(platform)
  241. .then((res) => {})
  242. .finally(() => (app.isLoading = false))
  243. },
  244. /**
  245. * 提交成功-跳转回原页面
  246. */
  247. onNavigateBack(delta) {
  248. uni.navigateBack({
  249. delta: Number(delta || 1)
  250. })
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. .container-login {
  257. padding: 30rpx 60rpx;
  258. padding-top: 200rpx;
  259. min-height: 100vh;
  260. background-color: #fff;
  261. }
  262. // 页面头部
  263. .header {
  264. margin-bottom: 50rpx;
  265. .title {
  266. color: #0081ff;
  267. font-size: 50rpx;
  268. font-weight: 900;
  269. }
  270. .sub-title {
  271. margin-top: 20rpx;
  272. color: #0080ffa9;
  273. font-size: 25rpx;
  274. }
  275. }
  276. .shiming {
  277. margin-top: 90rpx;
  278. }
  279. // 输入框元素
  280. .form-item {
  281. display: flex;
  282. padding: 18rpx;
  283. border-bottom: 1rpx solid #f3f1f2;
  284. margin-bottom: 25rpx;
  285. height: 96rpx;
  286. font-size: 30rpx;
  287. color: #333;
  288. &--input {
  289. font-size: 30rpx;
  290. letter-spacing: 1rpx;
  291. flex: 1;
  292. height: 100%;
  293. color: #333;
  294. }
  295. &--parts {
  296. min-width: 100rpx;
  297. height: 100%;
  298. }
  299. // 图形验证码
  300. .captcha {
  301. height: 100%;
  302. .image {
  303. display: block;
  304. width: 192rpx;
  305. height: 100%;
  306. }
  307. }
  308. // 短信验证码
  309. .captcha-sms {
  310. font-size: 30rpx;
  311. line-height: 50rpx;
  312. padding-right: 20rpx;
  313. .activate {
  314. color: #0081ff;
  315. }
  316. .un-activate {
  317. color: #9e9e9e;
  318. }
  319. }
  320. }
  321. // 提交按钮
  322. .submit-button {
  323. width: 100%;
  324. height: 86rpx;
  325. margin-top: 70rpx;
  326. background: linear-gradient(to right, $main-bg, $main-bg2);
  327. color: $main-text;
  328. border-radius: 80rpx;
  329. box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
  330. letter-spacing: 5rpx;
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. background-image: linear-gradient(-20deg, #b721ff 0%, #21d4fd 100%);
  335. }
  336. .form-dizhi {
  337. color: gray;
  338. }
  339. </style>