login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <view class="normal-login-container"
  3. style="background-image: url('https://jianyaoji.oss-cn-hangzhou.aliyuncs.com/jianyaoji/images/login/bg.png');background-size: 100% 100%;">
  4. <view class="logo-content align-center justify-center flex">
  5. <!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
  6. <!-- </image>-->
  7. <text class="title">老药师云平台移动端登录</text>
  8. </view>
  9. <view style="position: fixed;top:1vw;left:1vh;font-size: 12px;color: white;">
  10. 版本号:{{version}}
  11. </view>
  12. <view class="login-form-content">
  13. <view class="input-item flex align-center">
  14. <view class="iconfont icon-user icon"></view>
  15. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  16. </view>
  17. <view class="input-item flex align-center">
  18. <view class="iconfont icon-password icon"></view>
  19. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  20. </view>
  21. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  22. <view class="iconfont icon-code icon"></view>
  23. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  24. <view class="login-code">
  25. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  26. </view>
  27. </view>
  28. <view class="action-btn">
  29. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  30. </view>
  31. <view class="action-btn">
  32. <button class="login-btn cu-btn block lg round" open-type="getPhoneNumber"
  33. @getphonenumber="getPhoneNumber">客户注册</button>
  34. </view>
  35. </view>
  36. <view class="xieyi text-center">
  37. <!-- <text class="text-grey1">登录即代表同意</text>-->
  38. <!-- <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>-->
  39. <!-- <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>-->
  40. </view>
  41. <u-modal title="客户注册信息" @cancel="closeDlg" confirmText="提交审核" :showCancelButton="true" @confirm="submitReg"
  42. :show="show">
  43. <view class="slot-content">
  44. <u--form labelPosition="left" :model="model1" ref="s">
  45. <u-form-item label="客户名称:" prop="chooseUser.deptName" borderBottom ref="item1" labelWidth="auto">
  46. <u--input v-model="chooseUser.deptName" border="none"></u--input>
  47. </u-form-item>
  48. <u-form-item label="联系人:" prop="chooseUser.leader" borderBottom ref="item1" labelWidth="auto">
  49. <u--input v-model="chooseUser.leader" border="none"></u--input>
  50. </u-form-item>
  51. <u-form-item label="手机号:" prop="chooseUser.phone" borderBottom ref="item1" labelWidth="auto">
  52. <u--input v-model="chooseUser.phone" border="none"></u--input>
  53. </u-form-item>
  54. <u-form-item label="密码:" prop="chooseUser.password" borderBottom ref="item1" labelWidth="auto">
  55. <u--input v-if="show" v-model="chooseUser.password" border="none"></u--input>
  56. </u-form-item>
  57. <u-form-item label="登录账号:" borderBottom ref="item1" labelWidth="auto">
  58. <u--input v-model="chooseUser.phone" border="none" disabled></u--input>
  59. </u-form-item>
  60. <u-form-item label="订单图片:" borderBottom ref="item1" labelWidth="auto">
  61. <u-upload :fileList="fileList" name="1" multiple :maxCount="1" :previewFullImage="true"
  62. :width="auto" :height="auto" @delete="deletePic" @afterRead="afterRead"></u-upload>
  63. </u-form-item>
  64. </u--form>
  65. </view>
  66. </u-modal>
  67. <u-modal title="注册记录" @cancel="closereg" confirmText="重新注册" :showCancelButton="true" @confirm="submitRegTo"
  68. :show="registersshow">
  69. <view class="slot-content">
  70. <u--form labelPosition="left" :model="model1" ref="s">
  71. <u-form-item label="客户名称:" prop="registers.deptName" borderBottom ref="item1" labelWidth="auto">
  72. <u--input v-model="registers.deptName" border="none" :disabled="true"></u--input>
  73. </u-form-item>
  74. <u-form-item label="联系人:" prop="registers.leader" borderBottom ref="item1" labelWidth="auto">
  75. <u--input v-model="registers.leader" border="none" :disabled="true"></u--input>
  76. </u-form-item>
  77. <u-form-item label="手机号:" prop="registers.phone" borderBottom ref="item1" labelWidth="auto">
  78. <u--input v-model="registers.phone" border="none" :disabled="true"></u--input>
  79. </u-form-item>
  80. <u-form-item label="密码:" prop="registers.password" borderBottom ref="item1" labelWidth="auto">
  81. <u--input v-if="registersshow" v-model="registers.password" border="none"
  82. :disabled="true"></u--input>
  83. </u-form-item>
  84. <u-form-item label="登录账号:" borderBottom ref="item1" labelWidth="auto">
  85. <u--input v-model="registers.phone" border="none" disabled :disabled="true"></u--input>
  86. </u-form-item>
  87. <u-form-item label="注册状态:" borderBottom ref="item1" labelWidth="auto">
  88. <!-- this.registers.status==1&&this.registers.delFlag==0 -->
  89. <view v-if="registers.status==0" style="color:#1a62ff;">审核中</view>
  90. <view v-if="registers.status==1&&registers.delFlag==0">审核完成,<text
  91. style="color: crimson;">未通过原因:</text><text>{{registers.remark}}</text></view>
  92. </u-form-item>
  93. </u--form>
  94. </view>
  95. </u-modal>
  96. </view>
  97. </template>
  98. <script>
  99. import {
  100. getCodeImg,
  101. uploadRegister,
  102. getPhone,
  103. checkReg
  104. } from '@/api/login'
  105. import {
  106. getToken
  107. } from "@/utils/auth";
  108. import {
  109. checkStr
  110. } from "@/utils/validate";
  111. export default {
  112. data() {
  113. return {
  114. version: "",
  115. codeUrl: "",
  116. captchaEnabled: true,
  117. globalConfig: getApp().globalData.config,
  118. loginForm: {
  119. username: "",
  120. password: "",
  121. code: "",
  122. uuid: '',
  123. },
  124. show: false,
  125. chooseUser: {},
  126. fileList: [],
  127. registers: {},
  128. registersshow: false
  129. }
  130. },
  131. created() {
  132. this.show = false,
  133. this.getVersion();
  134. this.checkLogin();
  135. },
  136. methods: {
  137. getPhoneNumber(e) {
  138. console.log(e.detail.code) // 动态令牌
  139. // console.log(e.detail.code) // 动态令牌
  140. // console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
  141. // console.log(e.detail.errno) // 错误码(失败时返回)
  142. this.newUser(e.detail.code);
  143. },
  144. toRegister() {
  145. },
  146. submitReg() {
  147. //注册数据提交
  148. uploadRegister({
  149. formdata: this.chooseUser,
  150. name: 'register',
  151. file: this.fileList[0].url
  152. }).then(res => {
  153. uni.showToast({
  154. title: '注册信息已提交',
  155. duration: 2000
  156. });
  157. this.show = false
  158. })
  159. },
  160. deletePic(event) {
  161. this.fileList = []
  162. },
  163. async afterRead(file, lists, name) {
  164. //{"file":[{"size":542091,"type":"image","url":"http://tmp/MPgJgECRVMUFe49f23795545b0cd35400a9b70a9f918.jpg",
  165. //"thumb":"http://tmp/MPgJgECRVMUFe49f23795545b0cd35400a9b70a9f918.jpg"}],"name":"1","index":0}
  166. if (file.file[0].size > 2048 * 1000) {
  167. this.$modal.errMsg("图片大于2M")
  168. } else {
  169. this.fileList = file.file
  170. }
  171. },
  172. newUser(code) {
  173. let self = this
  174. uni.showLoading({
  175. title: '获取手机号...'
  176. });
  177. wx.login({
  178. success(res) {
  179. if (res.code) {
  180. let data = {
  181. loginCode: res.code,
  182. phoneCode: code
  183. }
  184. //获取到手机号
  185. getPhone(data).then(res => {
  186. //console.log("获取到手机号信息结果<>>" + JSON.stringify(res))
  187. if (checkStr(res.data.phone, 'mobile')) {
  188. //console.log("................" + res.data.phone)
  189. self.chooseUser.phone = res.data.phone
  190. self.chooseUser.openId = res.data.openId
  191. //通过手机号校验注册信息
  192. checkReg(res.data.phone).then(res => {
  193. //console.log("校验注册信息结果<>>" + JSON.stringify(res))
  194. if (res.data.code == 0) {
  195. //已注册待审核
  196. self.registers = res.data.res
  197. self.registersshow = true
  198. } else if (res.data.code == 1) {
  199. //已注册且通过审核,但是用户可能已被删除
  200. self.show = true;
  201. } else if (res.data.code == 2) {
  202. //未注册,进入注册页
  203. self.show = true;
  204. } else if(res.data.code==3){
  205. uni.showToast({
  206. title: '已存在客户信息',
  207. duration: 2000,
  208. icon:'none'
  209. });
  210. }else{
  211. //已注册未通过审核
  212. self.registers = res.data.res
  213. self.registersshow = true
  214. }
  215. uni.hideLoading();
  216. }).catch(res => {
  217. uni.showToast({
  218. title: '校验信息失败',
  219. duration: 2000,
  220. icon:'none'
  221. });
  222. })
  223. } else {
  224. uni.showToast({
  225. title: '手机号获取异常',
  226. duration: 2000,
  227. icon:'none'
  228. });
  229. }
  230. //self.show = true;
  231. }).catch(res => {
  232. uni.showToast({
  233. title: '获取手机号异常',
  234. duration: 2000,
  235. icon:'none'
  236. });
  237. })
  238. } else {
  239. console.log('获取code失败!' + res.errMsg)
  240. }
  241. }
  242. })
  243. },
  244. closereg() {
  245. this.registersshow = false
  246. this.registers = {}
  247. },
  248. submitRegTo() {
  249. //审核中
  250. if (this.registers.status == 0) {
  251. uni.showToast({
  252. title: '已在审核中...',
  253. duration: 1500,
  254. icon: 'loading'
  255. });
  256. this.registersshow = false
  257. this.show = false
  258. this.registers = {}
  259. } else if (this.registers.status == 1 && this.registers.delFlag == 0) {
  260. //审核完成且失败允许重新注册
  261. this.registersshow = false
  262. this.show = true
  263. }
  264. },
  265. closeDlg() {
  266. this.show = false;
  267. this.chooseUser = {};
  268. },
  269. checkLogin() {
  270. let token = getToken()
  271. if (token) {
  272. this.loginSuccess()
  273. } else {
  274. this.getCode()
  275. }
  276. },
  277. // 隐私协议
  278. handlePrivacy() {
  279. let site = this.globalConfig.appInfo.agreements[0]
  280. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  281. },
  282. // 用户协议
  283. handleUserAgrement() {
  284. let site = this.globalConfig.appInfo.agreements[1]
  285. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  286. },
  287. // 获取图形验证码
  288. getCode() {
  289. getCodeImg().then(res => {
  290. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  291. if (this.captchaEnabled) {
  292. this.codeUrl = 'data:image/gif;base64,' + res.img
  293. this.loginForm.uuid = res.uuid
  294. }
  295. })
  296. },
  297. getVersion() {
  298. let appBaseInfo = uni.getAppBaseInfo();
  299. let appVersionCode = appBaseInfo.appVersionCode;
  300. this.version = appVersionCode;
  301. },
  302. // 登录方法
  303. async handleLogin() {
  304. if (this.loginForm.username === "") {
  305. this.$modal.msgError("请输入您的账号")
  306. } else if (this.loginForm.password === "") {
  307. this.$modal.msgError("请输入您的密码")
  308. } else if (this.loginForm.code === "" && this.captchaEnabled) {
  309. this.$modal.msgError("请输入验证码")
  310. } else {
  311. this.$modal.loading("登录中,请耐心等待...")
  312. this.pwdLogin()
  313. }
  314. },
  315. // 密码登录
  316. async pwdLogin() {
  317. this.$store.dispatch('Login', this.loginForm).then(() => {
  318. this.$modal.closeLoading()
  319. this.loginSuccess()
  320. }).catch(() => {
  321. if (this.captchaEnabled) {
  322. this.getCode()
  323. }
  324. })
  325. },
  326. // 登录成功后,处理函数
  327. loginSuccess(result) {
  328. // 设置用户信息
  329. this.$store.dispatch('GetInfo').then(res => {
  330. this.$tab.reLaunch('/pages/work/index')
  331. })
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss">
  337. page {
  338. background-color: #ffffff;
  339. }
  340. .normal-login-container {
  341. width: 100%;
  342. position: absolute;
  343. top: 0px;
  344. bottom: 0;
  345. left: 0;
  346. right: 0;
  347. .logo-content {
  348. width: 100%;
  349. font-size: 21px;
  350. text-align: center;
  351. padding-top: 15%;
  352. image {
  353. border-radius: 4px;
  354. }
  355. .title {
  356. margin-left: 10px;
  357. color: #FFFFFF;
  358. font-size: 56rpx;
  359. }
  360. }
  361. .login-form-content {
  362. text-align: center;
  363. margin: 20px auto;
  364. margin-top: 15%;
  365. width: 90%;
  366. background: white;
  367. border-radius: 30rpx;
  368. box-shadow: 0rpx 5rpx 27rpx 0rpx rgba(195, 195, 195, 2.4);
  369. padding: 10%;
  370. .input-item {
  371. margin: 20px auto;
  372. background-color: #f5f6f7;
  373. height: 45px;
  374. border-radius: 20px;
  375. .icon {
  376. font-size: 38rpx;
  377. margin-left: 10px;
  378. color: #999;
  379. }
  380. .input {
  381. width: 100%;
  382. font-size: 14px;
  383. line-height: 20px;
  384. text-align: left;
  385. padding-left: 15px;
  386. //background: rgb(224,236,255);
  387. }
  388. }
  389. .login-btn {
  390. margin-top: 40px;
  391. height: 45px;
  392. }
  393. .xieyi {
  394. color: #333;
  395. margin-top: 20px;
  396. }
  397. .login-code {
  398. height: 38px;
  399. float: right;
  400. .login-code-img {
  401. height: 38px;
  402. position: absolute;
  403. margin-left: 10px;
  404. width: 200rpx;
  405. }
  406. }
  407. }
  408. }
  409. </style>