index.vue 12 KB

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