sign.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <image :src="login_top" mode="widthFix" class="width100" style="margin-top: -40upx;"></image>
  5. </view>
  6. <!-- <view class="logo-content align-center justify-center flex">
  7. <image :src="login_top" mode="widthFix" class="width100" style="margin-top: -80upx;"></image> -->
  8. <!-- <image :src="description" mode="widthFix" class="img_top"
  9. style="position: absolute;right: 0;top: 120upx; z-index: 999;width: 346upx;height: 330upx;"></image> -->
  10. <!-- </view> -->
  11. <!-- 账号密码框 -->
  12. <view class="login-form-content">
  13. <text style="color: #98AEAF;">角色</text>
  14. <view style="display: flex;margin: 15px auto;" class="u-demo-block__content">
  15. <u-checkbox-group placement="row" v-model="checkboxValue1" @change="checkboxChange"
  16. activeColor="#4CB2B6">
  17. <u-checkbox :customStyle="{margin:'0 0 8px 15px'}" v-for="(item, index) in checkboxList1"
  18. :key="index" :label="item.name" :name="item.name">
  19. </u-checkbox>
  20. </u-checkbox-group>
  21. </view>
  22. <text style="color: #98AEAF;">单位</text>
  23. <view class="u-demo-block__content" style="margin: 15px auto;">
  24. <view class="u-page__tag-item">
  25. <u-search @search="searchUnit" @custom="searchUnit" showAction placeholder="请搜索单位名称进行选择"
  26. v-model="loginForm.unit">
  27. </u-search>
  28. </view>
  29. </view>
  30. <text style="color: #98AEAF;">真实姓名</text>
  31. <view class="input-item flex align-center">
  32. <view class="iconfont icon-user icon"></view>
  33. <input v-model="loginForm.nickname" class="input" type="text" placeholder="请输入姓名" maxlength="30" />
  34. </view>
  35. <text style="color: #98AEAF;">账号</text>
  36. <view class="input-item flex align-center">
  37. <view class="iconfont icon-user icon"></view>
  38. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  39. </view>
  40. <text style="color: #98AEAF;">手机号</text>
  41. <view class="input-item flex align-center">
  42. <view class="iconfont icon-user icon"></view>
  43. <input v-model="loginForm.mobile" class="input" type="text" placeholder="请输入手机号" maxlength="30" />
  44. </view>
  45. <text style="color: #98AEAF;">密码</text>
  46. <view class="input-item flex align-center">
  47. <view class="iconfont icon-password icon"></view>
  48. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  49. </view>
  50. <text style="color: #98AEAF;">再次确认密码</text>
  51. <view class="input-item flex align-center">
  52. <view class="iconfont icon-password icon"></view>
  53. <input v-model="loginForm.passwords" type="password" class="input" placeholder="请确认密码" maxlength="20" />
  54. </view>
  55. <Verify @success="pwdLogin" :mode="'pop'" :captchaType="'blockPuzzle'"
  56. :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  57. <!-- 注册按钮 -->
  58. <view class="login-form-content2">
  59. <button @click="handleLogin" class="login-btn cu-btn block lg">确认注册</button>
  60. </view>
  61. </view>
  62. <u-picker :show="shows" :columns="columns1" @cancel="cancel" @confirm="confirm"></u-picker>
  63. <!-- <view class="xieyi text-center">
  64. <text class="text-grey1">登录即代表同意</text>
  65. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  66. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  67. </view> -->
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. addUser
  73. } from '@/api/staff_info'; //添加用户
  74. import {
  75. wxbind
  76. } from '@/api/login.js'; //微信绑定
  77. // #ifdef H5
  78. import Verify from '@/pagesA/components/verifition/Verify';
  79. // #endif
  80. import {
  81. getDepartUnit
  82. } from '@/api/login.js'
  83. import config from '@/config'
  84. const baseUrlImg=config.baseUrlImg
  85. export default {
  86. name: 'Login',
  87. components: {
  88. // #ifdef H5
  89. Verify
  90. // #endif
  91. },
  92. data() {
  93. return {
  94. shows: false, //单位搜索后的下拉框
  95. columns1: [
  96. ['未搜索到所属单位']
  97. ],
  98. searchData: [],
  99. checkboxValue1: [],
  100. // 基本案列数据
  101. checkboxList1: [{
  102. name: '管理者',
  103. disabled: false,
  104. },
  105. {
  106. name: '执行者',
  107. disabled: false
  108. }
  109. ],
  110. description: `${baseUrlImg}/login/description.png`, //登录页面顶部装饰图
  111. login_top:`${baseUrlImg}/login/login_top.png`, //登录页面顶部
  112. wx_login:`${baseUrlImg}/login/wx_login.png`, //登录按钮
  113. captchaEnabled: true, // 验证码开关 TODO 芋艿:需要抽到配置里
  114. canIUseGetUserProfile: false, // 用来判断用哪个登录
  115. globalConfig: getApp().globalData.config,
  116. userInfo: '',
  117. loginForm: {
  118. username: '',
  119. password: '',
  120. captchaVerification: '',
  121. socialCode: '',
  122. socialType: 34,
  123. socialState: '9b2ffbc1-7425-4155-9894-9d5c08541d62',
  124. orgId: '',
  125. unit: '',
  126. mobile: '',
  127. nickname: '', //真实姓名
  128. appRoleId: [],
  129. userId: '',
  130. realName: ''
  131. }
  132. };
  133. },
  134. onLoad(option) {
  135. this.loginForm.socialCode = option.socialCode
  136. //如果手机支持最新版登录就用新方法
  137. if (uni.getUserProfile) {
  138. this.canIUseGetUserProfile = true;
  139. }
  140. },
  141. methods: {
  142. checkboxChange(n) { //角色选择
  143. n.map(i => {
  144. if (i == '管理者') {
  145. this.loginForm.appRoleId.push('1')
  146. } else if (i == '执行者') {
  147. this.loginForm.appRoleId.push('2')
  148. } else {
  149. const arr = ["1", "2"]
  150. this.loginForm.appRoleId = arr
  151. }
  152. })
  153. },
  154. confirm(e) { //搜索单位确定
  155. this.loginForm.unit = e.value[0]
  156. this.searchData.map(i => {
  157. if (i.orgName == e.value[0] && i.orgName !== '未搜索到所属单位') {
  158. this.loginForm.orgId = i.id
  159. }
  160. })
  161. this.shows = false
  162. },
  163. cancel() {
  164. this.shows = false
  165. },
  166. //搜索单位
  167. searchUnit() {
  168. const org = this.loginForm.unit;
  169. getDepartUnit({
  170. orgName: org
  171. }).then(response => {
  172. // if (response.code == 0 && response.data.length == 0) {
  173. // this.$model.alert('暂无单位')
  174. // } else
  175. if (response.code == 0) {
  176. this.searchData = response.data
  177. this.shows = true
  178. response.data.map(i => {
  179. this.columns1[0].push(i.orgName)
  180. })
  181. }
  182. });
  183. },
  184. // 微信登录模块
  185. //老版登录接口(不再弹出登录弹框)
  186. bindGetUserInfo(e) {
  187. if (e.detail.userInfo) {
  188. //业务逻辑
  189. }
  190. },
  191. // 弹出登录弹框(新版)
  192. getUserProfiles() {},
  193. // 登录方法
  194. handleLogin(params) {
  195. if (this.loginForm.username === '') {
  196. this.$modal.msgError('请输入您的账号');
  197. } else if (this.loginForm.password === '') {
  198. this.$modal.msgError('请输入您的密码');
  199. } else if (this.loginForm.passwords === '') {
  200. this.$modal.msgError('请再次确认密码');
  201. } else if (this.loginForm.realname === '') {
  202. this.$modal.msgError('请输入您的真实姓名');
  203. } else if (this.loginForm.password != this.loginForm.passwords) {
  204. this.$modal.msgError('密码输入不一致,请重新输入');
  205. } else {
  206. this.pwdLogin({});
  207. }
  208. },
  209. // 密码登录
  210. async pwdLogin(captchaParams) {
  211. this.loginForm.appRoleId = [...new Set(this.loginForm.appRoleId)]
  212. addUser(JSON.stringify(this.loginForm)).then(reponse => {
  213. if (reponse.code == 0) {
  214. this.loginForm.userId = reponse.data
  215. this.loginForm.realName = this.loginForm.nickname
  216. wxbind(this.loginForm).then(res => {
  217. // 注册成功后 不用路由
  218. // this.$modal.loading('登录中,请耐心等待...');
  219. // 执行登录
  220. // console.log(this.loginForm, 'this.loginForm');
  221. this.loginForm.captchaVerification = captchaParams.captchaVerification;
  222. this.$store.dispatch('Login', this.loginForm).then(() => {
  223. this.$modal.closeLoading(); //关闭遮罩层
  224. this.loginSuccess();
  225. });
  226. })
  227. }
  228. })
  229. },
  230. // 登录成功后,处理函数
  231. loginSuccess(result) {
  232. this.$store.dispatch('loadDictDatas');
  233. // 设置用户信息
  234. this.$store.dispatch('GetInfo').then(res => {
  235. this.$tab.reLaunch('/pages/index');
  236. // this.$tab.reLaunch('/pages/work/index');
  237. });
  238. }
  239. }
  240. };
  241. </script>
  242. <style lang="scss">
  243. page {
  244. background-color: #ffffff;
  245. }
  246. .normal-login-container {
  247. width: 100%;
  248. .logo-content {
  249. width: 100%;
  250. font-size: 21px;
  251. text-align: center;
  252. image {
  253. border-radius: 4px;
  254. }
  255. .title {
  256. margin-left: 10px;
  257. }
  258. }
  259. .login-form-content {
  260. text-align: left;
  261. margin: 0 0 0 40rpx;
  262. margin-top: 0;
  263. width: 90%;
  264. .input-item {
  265. margin: 15px auto;
  266. background-color: #f5f9f7;
  267. height: 35px;
  268. border-radius: 20px;
  269. .icon {
  270. font-size: 38rpx;
  271. margin-left: 10px;
  272. color: #999;
  273. }
  274. .input {
  275. width: 100%;
  276. font-size: 14px;
  277. line-height: 18px;
  278. text-align: left;
  279. padding-left: 15px;
  280. }
  281. }
  282. /deep/ .u-search__content,
  283. /deep/.u-search__content__input {
  284. background-color: rgb(245, 249, 247) !important;
  285. }
  286. .login-btn {
  287. margin-top: 30px;
  288. height: 80upx;
  289. border-radius: 356upx;
  290. background-color: #4cb2b6;
  291. color: #ffffff;
  292. box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  293. }
  294. .xieyi {
  295. color: #333;
  296. margin-top: 20px;
  297. }
  298. }
  299. .easyinput {
  300. width: 100%;
  301. }
  302. }
  303. // 登录按钮
  304. .login-form-content2 {
  305. text-align: center;
  306. margin: 10px auto;
  307. margin-top: 0%;
  308. margin-bottom: 30rpx;
  309. width: 75%;
  310. .wx_login {
  311. height: 100upx;
  312. width: 450upx;
  313. // font-size: 16px;
  314. // padding-top: 2px;
  315. // background-color: #f5f7f9;
  316. // color: #728f90;
  317. // border-radius: 356upx;
  318. // box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  319. }
  320. .or {
  321. font-size: 20upx;
  322. margin: 20upx;
  323. color: #98aeaf;
  324. }
  325. }
  326. .login-code-img {
  327. height: 45px;
  328. }
  329. .wx_icon {
  330. position: relative;
  331. margin-top: 27%;
  332. margin-left: 42%;
  333. }
  334. </style>