index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="login">
  3. <image class="pic_dlbg" src="/static/img/pic_dlbg.png" mode=""></image>
  4. <view class="content1">
  5. <image class="pic_dl_hum" src="/static/img/pic_dl_hum.png" mode=""></image>
  6. <view class="title">潜山市教育局在线收发文系统</view>
  7. <!-- #ifdef MP-WEIXIN -->
  8. <view class="formContent">
  9. <view class="list">
  10. <view class="lable">账号</view>
  11. <view class="input">
  12. <u-input class="uInput" v-model="userData.username" type="text" placeholder="请输入您的账号" :border="false" />
  13. </view>
  14. </view>
  15. <view class="list">
  16. <view class="lable">密码</view>
  17. <view class="input">
  18. <u-input class="uInput" v-model="userData.password" type="password" placeholder="请输入您的密码" :border="false" />
  19. </view>
  20. </view>
  21. <view class="list">
  22. <xlSliderVerify @success="verifySuccess"></xlSliderVerify>
  23. </view>
  24. <view class="list">
  25. <view class="btn" @click="postLogin">登录</view>
  26. </view>
  27. </view>
  28. <!-- #endif -->
  29. <!-- #ifndef MP-WEIXIN -->
  30. <view class="formContent">
  31. <view class="list">
  32. <view class="lable">账号</view>
  33. <view class="input">
  34. <u-input class="uInput" v-model="userDataAPP.username" type="text" placeholder="请输入您的账号" :border="false" />
  35. </view>
  36. </view>
  37. <view class="list">
  38. <view class="lable">密码</view>
  39. <view class="input">
  40. <u-input class="uInput" v-model="userDataAPP.password" type="password" placeholder="请输入您的密码" :border="false" />
  41. </view>
  42. </view>
  43. <view class="list">
  44. <view class="lable">验证码</view>
  45. <view class="input">
  46. <u-input class="uInput" v-model="userDataAPP.code" type="text" placeholder="请输入验证码" :border="false" />
  47. <image :src="appcode" mode="" class="appcode" @click="appCode()"></image>
  48. </view>
  49. </view>
  50. <view class="list">
  51. <xlSliderVerify @success="verifySuccess"></xlSliderVerify>
  52. </view>
  53. <view class="list">
  54. <view class="btn" @click="postLoginAPP">登录</view>
  55. </view>
  56. </view>
  57. <!-- #endif -->
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import xlSliderVerify from '@/components/xl-slider-verify/xl-slider-verify.vue'
  63. export default {
  64. data() {
  65. return {
  66. userData: {
  67. username: '',
  68. password: '',
  69. code: ''
  70. },
  71. userDataAPP: {
  72. username: '',
  73. password: '',
  74. code: ''
  75. },
  76. isLogin: false,
  77. mainSwitch: false,
  78. tmpIds: [],
  79. appcode: '',
  80. appuuid: ''
  81. }
  82. },
  83. components:{
  84. xlSliderVerify
  85. },
  86. onLoad() {
  87. let that = this
  88. // #ifdef MP-WEIXIN
  89. wx.getSetting({
  90. withSubscriptions: true,
  91. success (res) {
  92. if (res.subscriptionsSetting.mainSwitch) {
  93. if (res.subscriptionsSetting.itemSettings != null) {
  94. that.mainSwitch = true
  95. for (var key in res.subscriptionsSetting.itemSettings) {
  96. that.tmpIds.push(key)
  97. }
  98. }
  99. }
  100. }
  101. })
  102. // #endif
  103. // #ifndef MP-WEIXIN
  104. this.appCode()
  105. // #endif
  106. },
  107. onShow() {
  108. let that = this
  109. // #ifdef MP-WEIXIN
  110. uni.login({
  111. provider: 'weixin',
  112. success: function(weixinRes) {
  113. that.userData.code = weixinRes.code
  114. console.log(weixinRes);
  115. }
  116. });
  117. // #endif
  118. },
  119. methods:{
  120. async postLogin () {
  121. if (!this.isLogin){
  122. uni.showToast({
  123. title: '请滑动验证条',
  124. icon: 'none'
  125. })
  126. return
  127. }
  128. let that = this
  129. let data = {
  130. username: that.userData.username,
  131. password: that.userData.password,
  132. code: that.userData.code,
  133. logintype: 'w'
  134. }
  135. let res = await that.$u.post('auth/login',data)
  136. if (res.code == 500) {
  137. uni.login({
  138. provider: 'weixin',
  139. success: function(weixinRes) {
  140. that.userData.code = weixinRes.code
  141. console.log(weixinRes);
  142. }
  143. });
  144. return false
  145. }
  146. console.log(res);
  147. uni.setStorage({
  148. key: 'authToken',
  149. data: res.data.access_token,
  150. success: async function() {
  151. uni.showToast({
  152. icon: 'none',
  153. title: '登陆成功'
  154. })
  155. // #ifdef MP-WEIXIN
  156. let res1 = await that.$u.get(`boman-wechat/wechat/p/c/tmpIds`, {})
  157. let dataList = []
  158. res1.data.forEach((item) => {
  159. if (that.tmpIds.indexOf(item) == -1) {
  160. dataList.push(item)
  161. }
  162. })
  163. if (that.mainSwitch && !dataList.length) {
  164. setTimeout( () => {
  165. uni.switchTab({
  166. url: '/pages/tabbar/index/index'
  167. })
  168. },2000)
  169. } else {
  170. wx.showModal({
  171. title: '提示',
  172. content: '订阅授权通知',
  173. success : function (res) {
  174. if (res.confirm) {
  175. wx.requestSubscribeMessage({
  176. tmplIds: dataList,
  177. success (resMessage) {
  178. uni.switchTab({
  179. url: '/pages/tabbar/index/index'
  180. })
  181. }
  182. })
  183. } else if (res.cancel) {
  184. console.log('用户点击取消')
  185. uni.switchTab({
  186. url: '/pages/tabbar/index/index'
  187. })
  188. }
  189. }
  190. })
  191. }
  192. // #endif
  193. }
  194. });
  195. },
  196. verifySuccess(e) {
  197. this.isLogin = true
  198. },
  199. async appCode() {
  200. let that = this
  201. let res = await that.$u.get('code')
  202. that.appcode = 'data:image/gif;base64,' + res.img
  203. that.appuuid = res.uuid
  204. },
  205. async postLoginAPP () {
  206. if (!this.isLogin){
  207. uni.showToast({
  208. title: '请滑动验证条',
  209. icon: 'none'
  210. })
  211. return
  212. }
  213. let that = this
  214. let data = {
  215. username: that.userDataAPP.username,
  216. password: that.userDataAPP.password,
  217. code: that.userDataAPP.code,
  218. uuid: that.appuuid,
  219. }
  220. let res = await that.$u.post('auth/login',data)
  221. uni.setStorage({
  222. key: 'authToken',
  223. data: res.data.access_token,
  224. success: async function() {
  225. uni.showToast({
  226. icon: 'none',
  227. title: '登陆成功'
  228. })
  229. setTimeout( () => {
  230. uni.switchTab({
  231. url: '/pages/tabbar/index/index'
  232. })
  233. },2000)
  234. },
  235. })
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .pic_dlbg{
  242. width: 100%;
  243. min-height: 100vh;
  244. }
  245. .content1{
  246. position: absolute;
  247. width: 100%;
  248. top: 0;
  249. left: 0;
  250. .pic_dl_hum{
  251. width: 510rpx;
  252. height: 356rpx;
  253. margin: 130rpx auto auto auto;
  254. }
  255. .title{
  256. font-size: 38rpx;
  257. color: #009FE8;
  258. font-weight: 700;
  259. text-align: center;
  260. margin-top: 16rpx;
  261. }
  262. .formContent{
  263. padding: 30rpx 78rpx;
  264. margin-top: 30rpx;
  265. .list{
  266. margin-bottom: 60rpx;
  267. position: relative;
  268. .lable{
  269. font-size: 28rpx;
  270. color: #343434;
  271. }
  272. .input{
  273. border-bottom: solid 2rpx #009FE8;
  274. padding: 10rpx 0;
  275. display: flex;
  276. align-items: center;
  277. .uInput{
  278. width: 100%;
  279. flex: 1;
  280. }
  281. .appcode{
  282. width: 200rpx;
  283. height: 60rpx;
  284. }
  285. }
  286. .btn {
  287. width: 100%;
  288. height: 90rpx;
  289. background: #009FE8;
  290. border-radius: 6rpx;
  291. color: #fff;
  292. line-height: 90rpx;
  293. text-align: center;
  294. }
  295. }
  296. }
  297. }
  298. </style>