loginPage.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <gui-page :is-loading="isLoading">
  3. <template #gBody>
  4. <view style="padding:50rpx;">
  5. <view class="server-config" @click="handleSetServerIP">
  6. <text class="font-icons">&#xe6bc;</text>
  7. </view>
  8. <view style="height:150rpx;" />
  9. <view class="gui-flex gui-row gui-justify-content-center login-title">
  10. <image src="../../static/logo.png" style="width: 90rpx;height: 90rpx;" mode="aspectFit" />
  11. <text class="login-title-text">东智-MOMPlus</text>
  12. <!-- <text
  13. class="login-logo gui-icons gui-color-white gui-block gui-border-box gui-bg-primary gui-box-shadow gui-box">&#xe620;</text> -->
  14. </view>
  15. <view style="margin-top:80rpx;">
  16. <form @submit="submit">
  17. <view>
  18. <text class="gui-text-small gui-color-gray">账户</text>
  19. </view>
  20. <view class="gui-border-b">
  21. <input
  22. v-model="loginForm.username"
  23. type="text"
  24. class="gui-form-input"
  25. name="username"
  26. placeholder="登录账户"
  27. >
  28. </view>
  29. <view class="gui-margin-top">
  30. <text class="gui-text-small gui-color-gray">密码</text>
  31. </view>
  32. <view class="gui-border-b">
  33. <input
  34. v-model="loginForm.password"
  35. type="password"
  36. class="gui-form-input"
  37. name="password"
  38. placeholder="密码"
  39. >
  40. </view>
  41. <view class="gui-margin-top gui-flex gui-rows gui-space-between" hover-class="gui-tap">
  42. <text class="gui-text gui-color-gray gui-block" @tap="forgetPwd">忘记密码</text>
  43. <text class="gui-text gui-color-gray gui-block gui-text-right" @tap="loginbymsg">短信登录</text>
  44. </view>
  45. <view style="margin-top:68rpx;">
  46. <button
  47. type="default"
  48. class="gui-button gui-bg-primary gui-noborder"
  49. formType="submit"
  50. style="border-radius:50rpx;"
  51. >
  52. <text class="gui-color-white gui-button-text">登 录</text>
  53. </button>
  54. </view>
  55. </form>
  56. </view>
  57. <!-- <view class="gui-flex gui-rows gui-nowrap gui-align-items-center"
  58. style="margin-top:80rpx; display: flex;justify-content: center;">
  59. <view class="gui-title-line"></view>
  60. <text class="gui-primary-color gui-h6"
  61. style="padding-left:50rpx; padding-right:50rpx;">其他方式登录</text>
  62. <view class="gui-title-line"></view>
  63. </view>
  64. <view class="gui-flex gui-rows gui-nowrap gui-justify-content-center gui-margin-top">
  65. <view hover-class="gui-tap">
  66. <text class="other-login-icons gui-icons gui-color-gray">&#xe63e;</text>
  67. </view>
  68. <view hover-class="gui-tap">
  69. <text class="other-login-icons gui-icons gui-color-gray">&#xe6cd;</text>
  70. </view>
  71. </view> -->
  72. </view>
  73. </template>
  74. </gui-page>
  75. </template>
  76. <script>
  77. import graceChecker from '@/Grace6/js/checker.js'
  78. import {
  79. getFileStorage
  80. } from '@/unit/fileStorage.js'
  81. export default {
  82. data() {
  83. return {
  84. isLoading: false,
  85. loginForm: {
  86. username: 'admin',
  87. password: 'admin123',
  88. // username: "",
  89. // password: "",
  90. validCode: 'akiooa'
  91. }
  92. }
  93. },
  94. beforeCreate() {
  95. // #ifdef APP-PLUS
  96. getFileStorage('serverConfig.txt')
  97. .then(data => {
  98. if (data === null) {
  99. uni.$baseUrl = ''
  100. } else {
  101. const ipconfig = JSON.parse(data)
  102. uni.$baseUrl = ipconfig.deal + '://' + ipconfig.ip + ':' + ipconfig.port
  103. }
  104. })
  105. .catch((e) => {
  106. uni.showToast({
  107. title: '获取服务配置失败, 请检查本地文件是否丢失',
  108. duration: 2000,
  109. icon: 'none'
  110. })
  111. })
  112. // #endif
  113. },
  114. methods: {
  115. forgetPwd: function() {},
  116. loginbymsg: function() {},
  117. handleSetServerIP: function() {
  118. uni.navigateTo({
  119. url: '/pages/personCenter/accountConfig'
  120. })
  121. },
  122. submit: async function(e) {
  123. // 表单数据
  124. var formData = e.detail.value
  125. // 利用 graceUI 的表单验证工具进行验证
  126. // 定义表单规则
  127. var rule = [{
  128. name: 'username',
  129. checkType: 'string',
  130. checkRule: '4,50',
  131. errorMsg: '登录账户输入有误, 至少4个字符'
  132. },
  133. {
  134. name: 'password',
  135. checkType: 'string',
  136. checkRule: '4,16',
  137. errorMsg: '登录密码至少4个字符'
  138. }
  139. ]
  140. var checkRes = graceChecker.check(formData, rule)
  141. if (checkRes) {
  142. uni.$grace.showLoading('登录中...')
  143. await uni.$reqPost('login', {
  144. ...formData,
  145. tenantName: '瑞泰克',
  146. tenantId: 1,
  147. rememberMe: true
  148. })
  149. .then(({
  150. code,
  151. data,
  152. msg
  153. }) => {
  154. if (code === 0) {
  155. uni.setStorageSync('token', data?.accessToken)
  156. // uni.setStorageSync("ACCESS_TOKEN", data?.accessToken);
  157. // uni.setStorageSync("REFRESH_TOKEN", data?.refreshToken);
  158. uni.$reqGet('loginInfo')
  159. .then(({
  160. data
  161. }) => {
  162. uni.setStorageSync('permissions', JSON.stringify(data?.permissions))
  163. uni.setStorageSync('user', JSON.stringify(data?.user))
  164. })
  165. uni.$emit('loginSuccess', true)
  166. uni.switchTab({
  167. url: '/pages/tabbar/tabbarPanel',
  168. success: function(e) { // 跳转成功后刷新页面
  169. // var page = getCurrentPages().pop()
  170. // if (page === undefined || page === null) return
  171. // page.onLoad();
  172. }
  173. })
  174. } else {
  175. uni.showToast({
  176. title: msg ?? '服务器配置错误!',
  177. duration: 2000,
  178. icon: 'none'
  179. })
  180. }
  181. })
  182. } else {
  183. uni.showToast({
  184. title: graceChecker.error,
  185. icon: 'none'
  186. })
  187. }
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .login-logo {
  194. width: 180rpx;
  195. height: 180rpx;
  196. font-size: 80rpx;
  197. text-align: center;
  198. line-height: 120rpx;
  199. padding: 30rpx;
  200. border-radius: 18rpx;
  201. }
  202. .login-title {
  203. height: 140rpx;
  204. display: flex;
  205. align-items: center;
  206. .login-title-text {
  207. font-size: 54rpx;
  208. font-weight: bold;
  209. color: rgba(0, 160, 233, 1);
  210. }
  211. }
  212. .other-login-icons {
  213. width: 88rpx;
  214. height: 88rpx;
  215. text-align: center;
  216. font-size: 70rpx;
  217. margin: 20rpx;
  218. }
  219. .server-config {
  220. position: fixed;
  221. top: 20px;
  222. right: 20px;
  223. text {
  224. font-size: 32px;
  225. color: #808080;
  226. }
  227. }
  228. </style>