diff --git a/.env.development b/.env.development index 1d451e7..5b6f2bd 100644 --- a/.env.development +++ b/.env.development @@ -5,7 +5,7 @@ VITE_APP_TITLE = 金武联驾校 VITE_APP_ENV = 'development' # 金武联驾校/开发环境 -VITE_APP_BASE_API = 'https://test.jd-mall.cn/dev/zongheng-api/' +VITE_APP_BASE_API = 'http://118.31.23.45:8888/' # -VITE_WEB_BASE_URL = 'https://test.jd-mall.cn/dev/zongheng' +VITE_WEB_BASE_URL = 'http://118.31.23.45:8888/' diff --git a/package.json b/package.json index 3fcf045..07e5a3e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "OA", + "name": "jwl", "version": "0.0.0", "scripts": { "dev:h5": "uni", @@ -15,7 +15,7 @@ "@dcloudio/uni-h5": "3.0.0-alpha-3060420220922001", "@dcloudio/uni-mp-weixin": "3.0.0-alpha-3060420220922001", "jsencrypt-plus": "^0.1.0", - "pinia": "^2.0.36", + "pinia": "2.0.36", "pinia-plugin-persist-uni": "^1.2.0", "vue": "^3.2.37", "vue-i18n": "^9.1.9" diff --git a/src/jtools/api/login.js b/src/jtools/api/login.js index 77eaf29..6c3f231 100644 --- a/src/jtools/api/login.js +++ b/src/jtools/api/login.js @@ -2,9 +2,25 @@ import request from '../request/index.js'; export function login(data) { return request({ - url: 'api-admin/pcLogin', + url: 'driver-api/tdSysUser/login', method: 'POST', data, noToken: true }); } + +export function getCode(data) { + return request({ + url: 'driver-api/tdSysUser/code', + method: 'get', + data, + noToken: true + }); +} + +export function logout() { + return request({ + url: 'driver-api/tdSysUser/loginOut', + method: 'get', + }); +} \ No newline at end of file diff --git a/src/jtools/api/vip.js b/src/jtools/api/vip.js new file mode 100644 index 0000000..ee5f469 --- /dev/null +++ b/src/jtools/api/vip.js @@ -0,0 +1,9 @@ +import request from '../request/index.js'; + +export function queryVip(data) { + return request({ + url: 'driver-api/tdMember/queryUserMember', + method: 'POST', + data, + }); +} \ No newline at end of file diff --git a/src/jtools/request/index.js b/src/jtools/request/index.js index 241d7de..f8e4f3c 100644 --- a/src/jtools/request/index.js +++ b/src/jtools/request/index.js @@ -1,4 +1,6 @@ import storage from '../storage/index.js'; +import useUserStore from '@/jtools/store/user' + //把配置项单独处理 let server_url = ' '; // 请求地址 let token = ' '; // 凭证 @@ -27,11 +29,15 @@ function service(options = {}) { title: res.data.message, icon: 'none' }); - uni.redirectTo({ - url: '/pages/login/login' - }); + useUserStore().logout() //请求成功 resolved(res.data); + } else if(res.data.code != '0000') { + uni.showToast({ + title: resp.message, + icon: 'none' + }) + resolved(res.data) } else { //请求成功 resolved(res.data); diff --git a/src/jtools/store/user.js b/src/jtools/store/user.js index d1fde67..bd845df 100644 --- a/src/jtools/store/user.js +++ b/src/jtools/store/user.js @@ -1,9 +1,9 @@ import { defineStore } from 'pinia'; -import http from '@/jtools/request/index'; +import { login,logout } from '@/jtools/api/login'; import constants from '@/jtools/constants'; import storage from '@/jtools/storage'; -const user = defineStore({ +const useUserStore = defineStore({ id: 'user', state: () => ({ token: storage.get('token'), @@ -12,57 +12,43 @@ const user = defineStore({ }), actions: { - // 登录 - showAuth() { - // router.replaceAll('/pages/login/login'); + login(params) { + // commit('isLogin', true); + return new Promise(async (resolve, reject) => { + const resp = await login(params); + if (resp.code === '0000') { + // 保存登录信息,用于重新登录 + this.isLogin = true; + this.token = resp.data.token; + this.userInfo = resp.data + storage.set('isLogin', true) + storage.set('token', resp.data.token) + storage.set('userInfo', resp.data) + resolve(resp.data); + } else { + reject(); + } + }); }, - - // 获取个人信息 - async getInfo() { - const { error, data } = await userApi.profile(); - if (error !== 0) return; - this.userInfo = data; - return Promise.resolve(data); - }, - - - // 设置token - setToken(token = '') { - if (token === '') { - this.isLogin = false; - this.token = '' - this.userInfo = {} - storage.set('token', ''); - storage.set('isLogin', false); - storage.set('userInfo', {}); - } else { - this.isLogin = true; - this.token = token - storage.set('token', token); - storage.set('isLogin', true); - } - return this.isLogin; - }, - - // 重置用户默认数据 - resetUserData() { - this.setToken(); - }, // 登出 - async logout(force = false) { - if (!force) { - const { error } = await userApi.logout(); - if (error === 0) { - this.resetUserData(); - } - } - if (force) { + logout(force = false) { + return new Promise((resolve, reject) => { this.resetUserData(); - } - - return !this.isLogin; + uni.redirectTo({ + url: '/pages/login/login' + }) + resolve(); + }) }, + resetUserData() { + this.isLogin = false; + this.token = ''; + this.userInfo = {} + storage.remove('isLogin') + storage.remove('token') + storage.remove('userInfo') + } }, }); -export default user; +export default useUserStore; diff --git a/src/jtools/utils/validate.js b/src/jtools/utils/validate.js new file mode 100644 index 0000000..bc0902e --- /dev/null +++ b/src/jtools/utils/validate.js @@ -0,0 +1,167 @@ +/** + * 判断url是否是http或https + * @param {string} path + * @returns {Boolean} + */ +export function isHttp(url) { + return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1; +} + +/** + * 判断path是否为外链 + * @param {string} path + * @returns {Boolean} + */ +export function isExternal(path) { + return /^(https?:|mailto:|tel:)/.test(path); +} + +/** + * @param {string} str + * @returns {Boolean} + */ +export function validUsername(str) { + const valid_map = ['admin', 'editor']; + return valid_map.indexOf(str.trim()) >= 0; +} + +/** + * @param {string} url + * @returns {Boolean} + */ +export function isURL(url) { + const reg = + /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/; + return reg.test(url); +} + +/** + * @param {string} str + * @returns {Boolean} + */ +export function validLowerCase(str) { + const reg = /^[a-z]+$/; + return reg.test(str); +} + +/** + * @param {string} str + * @returns {Boolean} + */ +export function validUpperCase(str) { + const reg = /^[A-Z]+$/; + return reg.test(str); +} + +/** + * @param {string} str + * @returns {Boolean} + */ +export function validAlphabets(str) { + const reg = /^[A-Za-z]+$/; + return reg.test(str); +} + +/** + * @param {string} email + * @returns {Boolean} + */ +export function isEmail(email) { + const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return reg.test(email); +} + +/** + * @param {string} str + * @returns {Boolean} + */ +export function isString(str) { + if (typeof str === 'string' || str instanceof String) { + return true; + } + return false; +} + +export function isPhone(str) { + return str && /^1[3456789]\d{9}$/.test(str) +} + +/** + * @param {Array} arg + * @returns {Boolean} + */ +export function isArray(arg) { + if (typeof Array.isArray === 'undefined') { + return Object.prototype.toString.call(arg) === '[object Array]'; + } + return Array.isArray(arg); +} + +// 是否纯英文 +export function isAllEN(val) { + return /^[a-zA-Z]*$/.test(val); +} + +// 是否纯中文 +export function isAllCN(val) { + return /^[\u4E00-\u9FA5]*$/.test(val); +} + +// 校验手机号 +export function validPhone(rule, value, callback) { + if (value && !/^1[3456789]\d{9}$/.test(value)) { + return callback(new Error('请输入正确的11位号码')); + } else { + return callback(); + } +} + +// 校验固话和手机号 +export function validPhoneAndMobile(rule, value, callback) { + if (value && !/^((0\d{2,3}-?\d{7,8})|(1[3465789]\d{9}))$/.test(value)) { + return callback(new Error('请输入正确的电话号码')); + } else { + return callback(); + } +} + +// 校验邮箱 +export function validEmail(rule, value, callback) { + if (value && !isEmail(value)) { + return callback(new Error('请输入正确的邮箱')); + } else { + return callback(); + } +} + +// 校验纳税人识别号 +export function validTaxpayer(rule, value, callback) { + if (value && !/^[A-Z0-9]{15}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/.test(value)) { + return callback(new Error('请输入正确的纳税人识别号')); + } else { + return callback(); + } +} + +// 校验是否网站 +export function validUrl(rule, value, callback) { + if (value && !isURL(value)) { + return callback(new Error('请输入正确的网站')); + } else { + return callback(); + } +} + +// 校验银行卡 +export function validBankCard(rule, value, callback) { + const strBin = '10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99'; + if (!value) { + return callback(); + } else if (!Number.isInteger(+value)) { + callback(new Error('银行卡号必须全为数字')); + } else if (value.trim().length < 8 || value.trim().length > 32) { + callback(new Error('银行卡号长度必须在8到32之间')); + } else { + callback(); + } +} diff --git a/src/main.js b/src/main.js index 3b3b5c3..8fbb63c 100644 --- a/src/main.js +++ b/src/main.js @@ -5,7 +5,7 @@ import uviewPlus from './uni_modules/uview-plus' import platform from '@/jtools/platform'; import constants from '@/jtools/constants'; import storage from '@/jtools/storage'; -import { createPinia } from 'pinia' +import * as Pinia from 'pinia' import App from "./App.vue"; export function createApp() { const app = createSSRApp(App); @@ -13,8 +13,9 @@ export function createApp() { app.config.globalProperties.$constants=constants app.config.globalProperties.$storage=storage app.use(uviewPlus) - app.use(createPinia()) + app.use(Pinia.createPinia()) return { app, + Pinia }; } diff --git a/src/pages.json b/src/pages.json index 3b05749..5a48211 100644 --- a/src/pages.json +++ b/src/pages.json @@ -97,13 +97,20 @@ "enablePullDownRefresh": false } }, - { - "path": "pages/index/videoVip", - "style": { - "navigationBarTitleText": "视频精品课", - "enablePullDownRefresh": false - } - } + { + "path": "pages/index/videoVip", + "style": { + "navigationBarTitleText": "视频精品课", + "enablePullDownRefresh": false + } + }, + { + "path": "pages/login/login", + "style": { + "navigationBarTitleText": "登录", + "enablePullDownRefresh": false + } + } ], "globalStyle": { diff --git a/src/pages/login/agreement.vue b/src/pages/login/agreement.vue deleted file mode 100644 index 2e8d56e..0000000 --- a/src/pages/login/agreement.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - - - diff --git a/src/pages/login/forget.vue b/src/pages/login/forget.vue deleted file mode 100644 index 83a4500..0000000 --- a/src/pages/login/forget.vue +++ /dev/null @@ -1,255 +0,0 @@ - - - - - diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index af57c29..d4a1d45 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -1,140 +1,162 @@ + page { + background-color: #fff; + } + + .content { + display: flex; + flex-direction: column; + justify-content: center; + } + + .header { + margin-top: 166rpx; + margin-left: auto; + margin-right: auto; + letter-spacing: 10rpx; + } + + .header image { + width: 383rpx; + } + + .list { + display: flex; + flex-direction: column; + padding-top: 120rpx; + padding-left: 90rpx; + padding-right: 90rpx; + } + + .list-call { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + height: 100rpx; + color: #333333; + border-bottom: 0.5px solid #e2e2e2; + } + + + + .list-call .sl-input { + flex: 1; + text-align: left; + font-size: 32rpx; + margin-left: 16rpx; + } + + .button-login { + color: #FFFFFF; + font-size: 34rpx; + width: 560rpx; + height: 100rpx; + background: linear-gradient(90deg, #11DF20 0%, #00B74F 100%); + border-radius: 50rpx; + line-height: 100rpx; + text-align: center; + margin-top: 100rpx; + margin-left: auto; + margin-right: auto; + } + + \ No newline at end of file diff --git a/src/pages/login/reg.vue b/src/pages/login/reg.vue deleted file mode 100644 index d51c945..0000000 --- a/src/pages/login/reg.vue +++ /dev/null @@ -1,303 +0,0 @@ - - - - - diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index 5d03cf4..e8ca953 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -3,14 +3,23 @@ - - + + - {{user.name}} + {{ user.userName }}{{user.userId}} - 陪您学车 第{{user.count}}天 + 陪您学车 第{{ user.count }}天 + + + + + + + 立即登录 + + 登录后获得更多学车信息 @@ -52,12 +61,12 @@ - + - + @@ -69,48 +78,83 @@ - + 退出登录