loginWeixin.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="content">
  3. <image class="logo" :src="avatarUrl"></image>
  4. <view class="title">
  5. {{nickName}}
  6. </view>
  7. <form @submit="loginwxSubmit">
  8. <view class="">
  9. <view class="title">角色选择</view>
  10. <radio-group class="level" name="level" @change="radioChange">
  11. <label class="radio">
  12. <radio class="radio" value="1" :checked="1==level" /><text>管理员</text>
  13. </label>
  14. </br>
  15. <label class="radio">
  16. <radio class="radio" value="2" :checked="2==level" /><text>员工</text>
  17. </label>
  18. </br>
  19. <label class="radio">
  20. <radio class="radio" value="3" :checked="3==level" /><text>游客</text>
  21. </label>
  22. </radio-group>
  23. </view>
  24. <view class="section" v-show="level==1">
  25. <input class="input-account" name="code" placeholder="管理员验证码" />
  26. </view>
  27. <view class="section" >
  28. <input class="input-account" name="workname" placeholder="员工名称" />
  29. </view>
  30. <view class="section">
  31. <input class="input-account" name="username" placeholder="请输入用户名" />
  32. </view>
  33. <view class="section" v-show="level<=2">
  34. <input class="input-pwd" password name="password" placeholder="请输入密码" />
  35. </view>
  36. <view class="btn-area">
  37. <button type="primary" formType="submit" :loading="isLoading">绑定微信</button>
  38. </view>
  39. </form>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. mapState
  46. } from 'vuex';
  47. import MD5 from '@/assets/scripts/md5';
  48. export default {
  49. data() {
  50. return {
  51. nickName: '',
  52. openId: '',
  53. avatarUrl: '',
  54. pname: '',
  55. password: '',
  56. level: 2,
  57. parm: {
  58. username: "",
  59. password: "",
  60. avatarUrl: "",
  61. nickName: "",
  62. openId: ""
  63. },
  64. keyEventBind: {
  65. backbutton: false, //Boolean(默认truee)关闭back按键监听
  66. menubutton: false //Boolean(默认true)关闭menu按键监听
  67. }
  68. };
  69. },
  70. onShow() {
  71. var weixinInfo = uni.getStorageSync("weixinInfo");
  72. this.nickName = weixinInfo.nickName;
  73. this.openId = weixinInfo.openId;
  74. this.avatarUrl = weixinInfo.avatarUrl;
  75. },
  76. computed: {
  77. ...mapState(['isLoading']),
  78. },
  79. methods: {
  80. loginwxSubmit(event) {
  81. uni.hideKeyboard();
  82. // const { value: loginForm } = event.detail;
  83. var username = event.detail.value.username;
  84. var pass = event.detail.value.password;
  85. var level = event.detail.value.level;
  86. var workname = event.detail.value.workname;
  87. if(level==2&&workname==""){
  88. uni.showModal({
  89. title: "提示",
  90. content: "员工名不能为空",
  91. success: function(res) {
  92. return;
  93. }
  94. })
  95. return;
  96. }
  97. var code = event.detail.value.code;
  98. if(level==1){
  99. if(code == "" || code==null){
  100. uni.showModal({
  101. title: "提示",
  102. content: "管理员需要输入验证码",
  103. success: function(res) {
  104. return;
  105. }
  106. })
  107. return;
  108. }
  109. if(code!="007"){
  110. uni.showModal({
  111. title: "提示",
  112. content: "验证码错误",
  113. success: function(res) {
  114. return;
  115. }
  116. })
  117. return;
  118. }
  119. }
  120. var password = MD5(pass);
  121. var serverUrl = this.serverurl;
  122. this.parm['username'] = username;
  123. this.parm['password'] = password;
  124. this.parm['level'] = level;
  125. this.parm['workName'] = workname;
  126. this.parm['avatarUrl'] = this.avatarUrl;
  127. this.parm['nickName'] = this.nickName;
  128. this.parm['openId'] = this.openId;
  129. // debugger;
  130. this.$store.dispatch('loginWXCZ', this.parm)
  131. .then(data => {
  132. var result = data.message;
  133. var weixinInfo = data.data;
  134. var code = data.code;
  135. uni.setStorageSync("token", data.token);
  136. uni.setStorageSync("globalUser", weixinInfo);
  137. uni.setStorageSync("level", this.level);
  138. if (code == true) {
  139. uni.reLaunch({
  140. url: '/pages/Charts/mainStatistics',
  141. });
  142. }
  143. }, _ => void uni.stopPullDownRefresh());
  144. },
  145. radioChange: function(evt) {
  146. this.level = evt.target.value;
  147. }
  148. },
  149. }
  150. </script>
  151. <style lang="scss">
  152. page {
  153. padding: 200upx 0 0 0;
  154. background-image: url('~@/static/backgrounds/login_bg.png');
  155. background-repeat: no-repeat;
  156. background-size: 100% 100%;
  157. position: absolute;
  158. top: 0;
  159. left: 0;
  160. right: 0;
  161. bottom: 0;
  162. .content {
  163. padding: 0 20upx;
  164. display: flex;
  165. flex-flow: column nowrap;
  166. align-items: center;
  167. .logo {
  168. width: 150upx;
  169. height: 150upx;
  170. text-align: center;
  171. margin: 50upx;
  172. }
  173. form {
  174. width: calc(100% - 100upx);
  175. padding: 50upx;
  176. .level {
  177. display: flex;
  178. flex-direction: row;
  179. }
  180. .radio {
  181. padding-top: 10upx;
  182. padding-left: 10upx;
  183. }
  184. .section {
  185. margin: 50upx 0;
  186. }
  187. .btn-area {
  188. margin-top: 100upx;
  189. button {
  190. background-color: $uni-color-primary;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. </style>