login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="loginbox">
  3. <view class="login_info">
  4. <view class="title">
  5. 登录
  6. </view>
  7. <u--form labelPosition="left" :model="userinfo" :rules="rules" ref="uForm">
  8. <u-form-item label="" prop="name" ref="item1">
  9. <u--input v-model="userinfo.name" border="none" placeholder="请输入账号"></u--input>
  10. </u-form-item>
  11. <u-form-item label="" prop="password" ref="item1">
  12. <u--input v-model="userinfo.password" border="none" placeholder="请输入密码" type="password"></u--input>
  13. </u-form-item>
  14. </u--form>
  15. <u-checkbox-group v-model="checkboxValue1" placement="column">
  16. <u-checkbox :customStyle="{marginBottom: '8px'}" label="记住密码" name="0" size="13" labelSize="13">
  17. </u-checkbox>
  18. </u-checkbox-group>
  19. <u-button type="primary" text="登录" @click="verify">{{isloading?"登录中...":"登录"}}</u-button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {mapMutations} from 'vuex'
  25. export default {
  26. data() {
  27. return {
  28. userinfo: {
  29. name: "",
  30. password: "",
  31. },
  32. rules: {
  33. 'name': {
  34. type: 'string',
  35. required: true,
  36. message: '请输入账号',
  37. trigger: ['blur', 'change']
  38. },
  39. 'password': {
  40. type: 'string',
  41. required: true,
  42. message: '请输入密码',
  43. trigger: ['blur', 'change']
  44. },
  45. },
  46. checkboxValue1: [],
  47. isloading: false
  48. }
  49. },
  50. methods: {
  51. ...mapMutations(['updateInLoginPageStatus']),
  52. verify() {
  53. this.$refs.uForm.validate().then(res => {
  54. // uni.$u.toast('校验通过')
  55. this.login()
  56. }).catch(errors => {
  57. // uni.$u.toast('校验失败')
  58. })
  59. },
  60. async getlistinfo() {
  61. var that = this
  62. const res = await this.$myRequest({
  63. url: '/api/api_gateway?method=sysmenage.usermanager.user_info',
  64. })
  65. // console.log(res)
  66. this.app = res.children.filter((item) => {
  67. return item.purview_name == "APP"
  68. })
  69. // console.log(this.app)
  70. if (this.app.length == 0) {
  71. uni.setTabBarItem({
  72. index: 0,
  73. visible: false
  74. });
  75. uni.setTabBarItem({
  76. index: 1,
  77. visible: false
  78. });
  79. uni.switchTab({
  80. url: "../response/index"
  81. })
  82. } else {
  83. var renwu = this.app[0].children.some((item) => {
  84. // console.log(item)
  85. return item.purview_name == "我的任务"
  86. })
  87. var jiandu = this.app[0].children.some((item) => {
  88. // console.log(item)
  89. return item.purview_name == "监督"
  90. })
  91. if (renwu) {
  92. uni.setTabBarItem({
  93. index: 0,
  94. visible: true
  95. });
  96. } else {
  97. uni.setTabBarItem({
  98. index: 0,
  99. visible: false
  100. });
  101. }
  102. if (jiandu) {
  103. uni.setTabBarItem({
  104. index: 1,
  105. visible: true
  106. });
  107. } else {
  108. uni.setTabBarItem({
  109. index: 1,
  110. visible: false
  111. });
  112. }
  113. if(renwu){
  114. uni.switchTab({
  115. url: "../index/index"
  116. })
  117. }else{
  118. uni.switchTab({
  119. url: "../supervise/index"
  120. })
  121. }
  122. }
  123. // #ifdef APP-PLUS
  124. plus.runtime.restart(); // 重启App
  125. console.log1p('重启App啦')
  126. // #endif
  127. },
  128. async login() {
  129. this.isloading = true
  130. const res = await this.$myRequest({
  131. url: '/api/api_gateway?method=sysmenage.usermanager.user_login',
  132. data: {
  133. username: this.userinfo.name,
  134. password: this.userinfo.password,
  135. }
  136. })
  137. console.log(res)
  138. if (res) {
  139. if (this.checkboxValue1.length) {
  140. uni.setStorage({
  141. key: 'logincheckbox',
  142. data: 1,
  143. })
  144. uni.setStorage({
  145. key: 'username',
  146. data: this.userinfo.name,
  147. })
  148. uni.setStorage({
  149. key: 'password',
  150. data: this.userinfo.password,
  151. })
  152. } else {
  153. uni.setStorage({
  154. key: 'logincheckbox',
  155. data: 0,
  156. })
  157. }
  158. uni.setStorage({
  159. key: 'session_key',
  160. data: res.session_key,
  161. success: () => {
  162. this.getlistinfo()
  163. }
  164. })
  165. }else{
  166. console.log("登陆失败")
  167. }
  168. },
  169. },
  170. onShow() {
  171. this.isloading = false
  172. },
  173. onLoad() {
  174. this.updateInLoginPageStatus(true)
  175. this.isloading = false
  176. uni.getStorage({
  177. key: 'logincheckbox',
  178. success: (res) => {
  179. console.log(res)
  180. if (res.data) {
  181. this.checkboxValue1 = ["0"]
  182. uni.getStorage({
  183. key: 'username',
  184. success: (res) => {
  185. this.userinfo.name = res.data
  186. },
  187. })
  188. uni.getStorage({
  189. key: 'password',
  190. success: (res) => {
  191. this.userinfo.password = res.data
  192. },
  193. })
  194. uni.getStorage({
  195. key: 'session_key',
  196. success: (res) => {
  197. console.log(res)
  198. uni.removeStorage({
  199. key: 'session_key'
  200. })
  201. if (res.data != "") {
  202. this.login()
  203. }
  204. },
  205. })
  206. } else {
  207. this.checkboxValue1 = []
  208. }
  209. },
  210. })
  211. },
  212. mounted() {
  213. this.updateInLoginPageStatus(true)
  214. },
  215. onHide(){
  216. console.log('login page hide')
  217. this.updateInLoginPageStatus(false)
  218. }
  219. }
  220. </script>
  221. <style lang="less">
  222. .loginbox {
  223. width: 100%;
  224. height: 100vh;
  225. background-image: url(../../static/image/login.jpg);
  226. background-size: 100% 100%;
  227. padding-top: 400rpx;
  228. box-sizing: border-box;
  229. .login_info {
  230. width: 90%;
  231. margin: 0 auto;
  232. height: 600rpx;
  233. background-color: #fff;
  234. box-shadow: 0px 0px 8px rgba(64, 158, 255, 0.1);
  235. padding: 40rpx 80rpx;
  236. box-sizing: border-box;
  237. border-radius: 20rpx;
  238. .title {
  239. width: 100%;
  240. height: 100rpx;
  241. text-align: center;
  242. line-height: 100rpx;
  243. font-size: 50rpx;
  244. color: #409EFF;
  245. margin-bottom: 30px;
  246. }
  247. /deep/.u-form-item__body {
  248. margin-bottom: 40rpx;
  249. border-bottom: 1px solid rgb(214, 215, 217);
  250. }
  251. /deep/.u-button {
  252. margin-top: 40rpx;
  253. border-radius: 38rpx;
  254. }
  255. // /deep/.u-checkbox__icon-wrap{
  256. // width: 26rpx !important;
  257. // height: 26rpx !important;
  258. // }
  259. }
  260. }
  261. </style>