index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view style="width: 100%;height: 100%;">
  3. <image src="../../static/images/card.jpg" style="width: 100%;height: 100%;" mode="scaleToFill"
  4. @click="keyHideStatus">
  5. <uni-forms ref="baseForm" id="form1" :modelValue="formData" :rules="rules">
  6. <view class="cardBody">
  7. <view class="card " :style="'height:'+height+' ;'">
  8. <view class="phoneText global-font" @click="keyHideStatus">
  9. 账号
  10. </view>
  11. <view @click="keyHideStatus">
  12. <uni-forms-item name="username">
  13. <input class="inputClass" :style="'height:'+inputHeight+';'" ref="userInput"
  14. v-model="formData.username" :adjust-position="false" @focus="openUsername"
  15. @blur="closeUsername" />
  16. </uni-forms-item>
  17. </view>
  18. <view class="phoneText global-font" @click="keyHideStatus">
  19. 密码(初始密码为身份证号后6位)
  20. </view>
  21. <view>
  22. <uni-forms-item name="password">
  23. <input id="ins" class="inputClass" :style="'height:'+inputHeight+';'"
  24. v-model="formData.password" :password="showPassword" @blur="close()"
  25. @focus="open" />
  26. <tki-float-keyboard ref="keyb" :mode="keyMode" :type="keyType" :title="title"
  27. @del="keyDel" @val="keyVal" @show="keyShow" @hide="keyHide"></tki-float-keyboard>
  28. </uni-forms-item>
  29. </view>
  30. <view>
  31. <button class="buttonClass" @click="to">登录</button>
  32. </view>
  33. <!-- <view class="zcText">
  34. <text class="global-font" @click="register">注册账号</text>
  35. </view> -->
  36. <view class="mzText" id="protocol">
  37. <radio :checked="protocol" @click="radioChange"></radio>
  38. <view class="global-font">已阅读并同意</view>
  39. <view class="global-font">
  40. <navigator url="/pages/protocol/yonghuxieyi" hover-class="none">《用户协议》</navigator>
  41. </view>
  42. <view class="global-font">和</view>
  43. <view class="global-font">
  44. <navigator url="/pages/protocol/yinsizhengce" hover-class="none">《隐私政策》</navigator>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </uni-forms>
  50. </image>
  51. </view>
  52. </template>
  53. <script>
  54. import config from '@/config.js'
  55. import {
  56. setToken,
  57. setOpenid,
  58. setUser,
  59. getOpenid
  60. } from '@/common/auth.js'
  61. import {
  62. Login,
  63. GetOpenId
  64. } from '@/api/login.js'
  65. import {
  66. showConfirm
  67. } from '../../common/common'
  68. import tkiFloatKeyboard from '@/components/tki-float-keyboard/tki-float-keyboard.vue'
  69. export default {
  70. components: {
  71. tkiFloatKeyboard
  72. },
  73. data() {
  74. return {
  75. // 键盘
  76. // 键盘类型 keyboard 普通键盘,car 汽车键盘,number 数字键盘
  77. keyMode: 'keyboard',
  78. // type 键盘可用区域,配合mode属性使用 默认值:0
  79. //mode = keyboard 时 type = 0 全部、 1 字母加数字、 2 符号、 3 字母、 4 数字、 5 字母加符号、6 数字加符号
  80. //mode = car 时 type = 0 全部、 1 字母加数字、 2 省、 3 字母加数字加特、 4 字母、 5 数字
  81. //mode = number 时 type = 0 全部、 1 禁用.
  82. keyType: 0,
  83. title: '密码键盘',
  84. keyShowStatus: false,
  85. showPassword: true,
  86. height: '42vh',
  87. inputHeight: '5vh',
  88. formData: {
  89. // username: 'lrry220103000000',
  90. // password: 'sckj12356',
  91. username: '',
  92. password: '',
  93. // code: "081X2kll21UGPc4HRlml27WxeO3X2kl6",
  94. username: '15143018068',
  95. password: 'sckj12356',
  96. openid: "",
  97. },
  98. rules: {
  99. username: {
  100. rules: [{
  101. required: true,
  102. errorMessage: '账号不能为空'
  103. }]
  104. },
  105. password: {
  106. rules: [{
  107. required: true,
  108. errorMessage: '密码不能为空'
  109. }]
  110. },
  111. },
  112. defaultPhoneHeight: '', //屏幕默认高度
  113. nowPhoneHeight: '', //屏幕现在的高度
  114. show: false,
  115. protocol: false,
  116. }
  117. },
  118. onLoad() {
  119. // 测试openid
  120. // setOpenid('owaO0uKdXNGMx7Zsy2jOZ0ZKsJGs')
  121. if (!getOpenid()) {
  122. this.getCode(config.appid)
  123. }
  124. },
  125. mounted() {
  126. //监听软键盘获取当前屏幕高度的事件
  127. this.defaultPhoneHeight = window.innerHeight
  128. window.onresize = () => {
  129. this.nowPhoneHeight = window.innerHeight
  130. }
  131. },
  132. watch: {
  133. //软键盘弹起事件
  134. nowPhoneHeight() {
  135. if (this.defaultPhoneHeight != this.nowPhoneHeight) {
  136. //手机键盘被唤起了。
  137. this.show = true
  138. } else {
  139. //手机键盘被关闭了。
  140. this.show = false
  141. }
  142. }
  143. },
  144. methods: {
  145. radioChange(e) {
  146. console.log("123", e);
  147. this.protocol = !this.protocol
  148. },
  149. openUsername() {
  150. setTimeout(() => {
  151. if (this.show) {
  152. this.height = '58vh'
  153. this.inputHeight = '8vh'
  154. }
  155. }, 140)
  156. },
  157. closeUsername() {
  158. this.height = '42vh'
  159. this.inputHeight = '5vh'
  160. },
  161. keyHideStatus() {
  162. if (this.keyShowStatus) this.$refs.keyb._keyHide()
  163. },
  164. keyVal(v) {
  165. this.formData.password += v
  166. },
  167. keyDel(d) {
  168. this.formData.password = this.formData.password.substring(0, this.formData.password.length - 1)
  169. },
  170. keyShow(h) {
  171. this.keyShowStatus = true
  172. },
  173. keyHide(h) {
  174. this.keyShowStatus = false
  175. },
  176. change(e) {
  177. this.formData.password += e
  178. console.log('change', e)
  179. },
  180. confirm(e) {
  181. console.log('confirm', e)
  182. },
  183. backspace(e) {
  184. this.formData.password = this.formData.password.substring(0, this.formData.password.length - 1)
  185. console.log('backspace', e)
  186. },
  187. changeCarInputMode(e) {
  188. this.title = e;
  189. },
  190. open() {
  191. uni.hideKeyboard()
  192. this.$refs.keyb._keyShow();
  193. console.log("打开");
  194. },
  195. close() {
  196. console.log("关闭");
  197. },
  198. register() {
  199. if (!this.protocol) {
  200. let ele = document.getElementById('protocol')
  201. if (ele) {
  202. ele.classList.add('shake')
  203. setTimeout(() => {
  204. ele.classList.remove('shake')
  205. }, 800)
  206. }
  207. return
  208. }
  209. uni.navigateTo({
  210. url: '/pages/lr/register?code=' + this.formData.code
  211. // url: '/pages/info/add?code=' + this.formData.code
  212. })
  213. },
  214. getCode(appid) { // 非静默授权,第一次有弹框
  215. let local = window.location.href; // 获取页面url
  216. console.log("local:", local, appid)
  217. let code = this.getUrlCode().code; // 截取code
  218. if (code && code !== '') { // 如果有code
  219. // 拿到code去请求openId并存在本地 ?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
  220. GetOpenId({
  221. code: code
  222. }).then(res => {
  223. setOpenid(res.data)
  224. this.formData.openid = res.data
  225. })
  226. }
  227. // else {
  228. // window.location.href =
  229. // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_base&state=${new Date().getTime()}#wechat_redirect`
  230. // }
  231. },
  232. getUrlCode() { // 截取url中的code方法
  233. let url = location.search;
  234. console.log("utl:", url)
  235. let theRequest = {};
  236. if (url.indexOf("?") !== -1) {
  237. console.log("utl1:", url)
  238. let str = url.substr(1);
  239. let strs = str.split("&");
  240. for (let i = 0; i < strs.length; i++) {
  241. theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1])
  242. }
  243. }
  244. console.log("theRequest:", theRequest)
  245. return theRequest
  246. },
  247. to() {
  248. if (!this.protocol) {
  249. let ele = document.getElementById('protocol')
  250. if (ele) {
  251. ele.classList.add('shake')
  252. setTimeout(() => {
  253. ele.classList.remove('shake')
  254. }, 800)
  255. }
  256. return
  257. }
  258. uni.hideKeyboard()
  259. this.$refs['baseForm'].validate().then(res => {
  260. uni.showLoading({
  261. title: '登录中...'
  262. })
  263. if (!this.formData.openid) this.formData.openid = getOpenid()
  264. Login(this.formData).then(e => {
  265. uni.hideLoading()
  266. if (e.code == 200) {
  267. setUser(e.data.sysUser)
  268. setToken(e.data.token.access_token)
  269. uni.switchTab({
  270. url: '/pages/index/index'
  271. })
  272. // uni.navigateTo({
  273. // url:'/pages/test/index'
  274. // })
  275. }
  276. })
  277. }).catch(err => {
  278. console.log(err);
  279. })
  280. }
  281. }
  282. }
  283. </script>
  284. <style scoped>
  285. .cardBody {
  286. display: flex;
  287. align-items: center;
  288. flex-direction: column;
  289. position: absolute;
  290. /* bottom: 20vh; */
  291. top: 37vh;
  292. left: 12vw;
  293. }
  294. .card {
  295. width: 76vw;
  296. /* height: 42vh; */
  297. border-radius: 2.8vw;
  298. background: rgba(255, 255, 255, 1);
  299. box-shadow: 5px 6px 18px rgba(0, 0, 0, 0.08);
  300. }
  301. .phoneText {
  302. margin-top: 3vh;
  303. margin-left: 4vw;
  304. width: 80vw;
  305. height: 3vh;
  306. font-size: 2.8vw;
  307. line-height: 2vh;
  308. color: rgba(116, 127, 158, 1);
  309. text-align: left;
  310. vertical-align: top;
  311. }
  312. .global-font {}
  313. .zcText {
  314. position: absolute;
  315. margin-top: 2vh;
  316. margin-left: 4vw;
  317. width: 68vw;
  318. height: 5vh;
  319. font-size: 2.8vw;
  320. color: rgba(116, 127, 158, 1);
  321. font-weight: 500;
  322. line-height: 2vh;
  323. text-align: center;
  324. vertical-align: top;
  325. }
  326. .inputClass {
  327. margin-top: 1vh;
  328. margin-left: 4vw;
  329. width: 68vw;
  330. /* height: 5vh; */
  331. border-radius: 5.8vw;
  332. border: 1px solid rgba(176, 179, 199, 1);
  333. text-indent: 4vw;
  334. }
  335. .buttonClass {
  336. margin-top: 4vh;
  337. margin-left: 4vw;
  338. width: 68vw;
  339. /* height: 5vh; */
  340. display: flex;
  341. justify-content: center;
  342. align-items: center;
  343. border-radius: 5.8vw;
  344. /* border: 1px solid rgba(176, 179, 199, 1); */
  345. background: #28d87d;
  346. color: white;
  347. height: 5vh;
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. box-shadow:0rpx 4rpx 10rpx 1rpx rgba(40, 216, 125,0.4);
  352. }
  353. .mzText {
  354. position: absolute;
  355. margin-top: 4vh;
  356. margin-left: 4vw;
  357. width: 68vw;
  358. height: 5vh;
  359. font-size: 2.8vw;
  360. color: rgba(116, 127, 158, 1);
  361. font-weight: 500;
  362. line-height: 2vh;
  363. text-align: center;
  364. vertical-align: top;
  365. display: flex;
  366. align-items: center;
  367. }
  368. radio {
  369. transform: scale(0.7);
  370. }
  371. .shake {
  372. animation: shake 800ms ease-in-out;
  373. }
  374. @keyframes shake {
  375. 10%,
  376. 90% {
  377. transform: translate3d(-1px, 0, 0);
  378. }
  379. 20%,
  380. 80% {
  381. transform: translate3d(+2px, 0, 0);
  382. }
  383. 30%,
  384. 70% {
  385. transform: translate3d(-4px, 0, 0);
  386. }
  387. 40%,
  388. 60% {
  389. transform: translate3d(+4px, 0, 0);
  390. }
  391. 50% {
  392. transform: translate3d(-4px, 0, 0);
  393. }
  394. }
  395. </style>