Browse Source

[完成] 供应商登录

[完成] 供应商首页接口对接
master
邓平艺 5 years ago
parent
commit
18740bdd1e
  1. 71
      App.vue
  2. 10
      common/api.js
  3. 9
      common/http.interceptor.js
  4. 20
      common/http.js
  5. 55
      common/mixin.js
  6. 6
      manifest.json
  7. 20
      pages.json
  8. 28
      pages/empty/index.vue
  9. 66
      pages/supply/index/index.vue
  10. 37
      pages/supply/login/index.vue

71
App.vue

@ -1,7 +1,6 @@
<script>
export default {
globalData: {
wxlogin: () => {}, //
screenWidth: 0, //
statusBarH: 0, //
screenHeight: 0, //
@ -11,12 +10,6 @@
onLaunch: function() {
this.disableConsole();
this.getSystemInfo();
// this.getUserInfo();
},
onShow: function() {
// #ifdef MP-WEIXIN
this.getUpdateWexin(); //
// #endif
},
methods: {
//
@ -41,70 +34,6 @@
this.globalData.customBarH = res.statusBarHeight + res.titleBarHeight;
// #endif
},
//
getUserInfo(){
this.globalData.wxlogin = this.wxlogin;
//
let userinfo = uni.getStorageSync('userinfo');
if(userinfo && userinfo.id){
return;
}
this.globalData.wxlogin();
},
wxlogin(){
return new Promise((resolve, rejecj) => {
uni.login({
complete: result => {
if(result.errMsg == 'login:ok'){
let code = result.code;
this.$http(this.API.API_WXLOGIN, { code }).then(res => {
console.log("获得用户信息", res);
uni.setStorageSync('userinfo', res.data);
resolve(res.data);
})
}
}
})
})
},
//
getUpdateWexin(){
const updateManager = uni.getUpdateManager(); //
updateManager.onCheckForUpdate(function(res) {
//
if (res.hasUpdate) {
updateManager.onUpdateReady(function(res2) {
uni.showModal({
title: '更新提示',
content: '发现新版本,是否重启应用?',
confirmColor: '#FE9903',
showCancel: false,
success(res2) {
if (res2.confirm) {
// applyUpdate
updateManager.applyUpdate();
}
}
});
});
}
});
updateManager.onUpdateFailed(function(res) {
//
uni.showModal({
title: '提示',
content: '检查到有新版本,但下载失败,请检查网络设置',
confirmColor: '#FE9903',
success(res) {
if (res.confirm) {
// applyUpdate
updateManager.applyUpdate();
}
}
});
});
},
// console
disableConsole(){
if(this.API.DEV == 'prod'){

10
common/api.js

@ -1,5 +1,13 @@
// appId: 正式 null | 测试 null
export const DEV = "dev"; // dev 测试 | prod 正式
export const VERSION = '1.0.0'; // 版本号
export const DEVURL = ''; // 测试服请求地址
export const DEVURL = 'http://192.168.3.29'; // 测试服请求地址
export const PRODURL = ''; // 正式服请求地址
/* 供应商相关接口 */
export const API_SUPPLIER_INDEX = '/api/supplier/index'; // 落地页
export const API_SUPPLIER_LOGIN = '/api/supplier/login'; // 登录
export const API_SUPPLIER_MATERIALLIST = '/api/supplier/materialList'; // 物资列表
export const API_SUPPLIER_QUOTATIONAPPLY = '/api/supplier/quotationApply'; // 申请报价
export const API_SUPPLIER_QUOTATIONORDERLIST = '/api/supplier/quotationOrderList'; // 申请报价-订单列表
export const API_SUPPLIER_PURCHASEORDERLIST = '/api/supplier/purchaseOrderList'; // 供货订单列表

9
common/http.interceptor.js

@ -16,7 +16,13 @@ const install = (Vue, vm) => {
// 请求前拦截, 现在不做拦截
Vue.prototype.$u.http.interceptor.request = config => {
return true;
// console.log("config", config, config.url)
// TODO 缺少食堂端config.url判断
if(!config.data.token && config.url != '/api/supplier/login'){
return false;
}else{
return true;
}
};
// 响应拦截
@ -27,7 +33,6 @@ const install = (Vue, vm) => {
vm.$msg(res.msg);
return false;
}
// res.code == 9998 手机号 res.code == 9999 用户信息
}
}

20
common/http.js

@ -40,7 +40,7 @@ function $http(url, data = {}, options = {}){
data.rand = Math.round(Math.random() * 1000000);
}
// 当前请求来自的平台
data.platform = 'wxmini';
data.platform = 'h5';
// #ifdef APP-PLUS
data.platform = 'app'; // 来自app平台,其他平台写法类似
// #endif
@ -62,13 +62,17 @@ function $http(url, data = {}, options = {}){
if (sysInfo) {
data.device_info = JSON.stringify(sysInfo);
}
// 判断传入用户token和id
let userinfo = uni.getStorageSync('userinfo') || {};
if(userinfo && userinfo.token && !data.token){
data.token = userinfo.token;
}
if(userinfo && userinfo.id && !data.user_id){
data.user_id = userinfo.id;
// 判断传入用户token
if(that.$getPageType() == 'supply'){
let user_token = uni.getStorageSync('supply_token');
if(user_token && !data.token){
data.token = user_token;
}
}else if(that.$getPageType() == 'canteen'){
let user_token = uni.getStorageSync('canteen_token');
if(user_token && !data.token){
data.token = user_token;
}
}
// 获取页面options参数

55
common/mixin.js

@ -2,12 +2,30 @@ export default{
data(){
return {
pageScrollTop: 0, // 页面距离顶部的距离
currentPage: '' // 当前页面路径
}
},
onPageScroll(res) {
this.pageScrollTop = res.scrollTop;
},
onLoad(){
let pages = getCurrentPages(); // 获取页面栈
this.currentPage = pages[pages.length - 1].route; // 当前页面
let key_name = this.$getPageType() +'_token';
let user_token = uni.getStorageSync(key_name);
if(!user_token){
this.$redirectToLogin();
}
},
methods: {
$getPageType(){
// 获取当前页面是属于供应端还是食堂端
if(this.currentPage.indexOf('pages/supply') == 0){
return 'supply';
}else if(this.currentPage.indexOf('pages/canteen') == 0){
return 'canteen';
}
},
$isRight(val){
return this.$shared.isRight(val);
},
@ -57,13 +75,23 @@ export default{
}
},
$msg(title = '', param = {}) {
if(!title) return;
uni.showToast({
title,
duration: param.duration || 1500,
mask: param.mask || true, // 默认应该加mask 禁止提示时操作
icon: param.icon || 'none'
});
return new Promise((resolve, reject) => {
if(!title){
reject();
return;
}
uni.showToast({
title,
duration: param.duration || 1500,
mask: param.mask || true, // 默认应该加mask 禁止提示时操作
icon: param.icon || 'none',
complete: result => {
setTimeout(() => {
resolve();
}, param.duration || 1500);
}
});
})
},
$url(url, options = {}){
this.$u.throttle(() => {
@ -86,8 +114,19 @@ export default{
if(beforePage && beforePage.route){
uni.navigateBack();
}else{
uni.switchTab({url:'/pages/index/index'});
let path_url = '/pages/'+ this.$getPageType() +'/index/index';
this.$url(path_url, {type: 'launch'});
}
},
$redirectToLogin(text){
let path_url = '/pages/'+ this.$getPageType() +'/login/index';
if(path_url == '/'+ this.currentPage || this.currentPage == 'pages/empty/index'){
return;
}
text = text || '您的状态异常, 即将跳转...';
this.$msg(text, {duration: 800}).then(() => {
this.$url(path_url, {type: 'launch'}); // 重定向到登录页
})
}
}
}

6
manifest.json

@ -70,5 +70,11 @@
},
"uniStatistics" : {
"enable" : false
},
"h5" : {
"router" : {
"mode" : "history",
"base" : "./"
}
}
}

20
pages.json

@ -3,6 +3,13 @@
"^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue"
},
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path": "pages/supply/index/index",
"style": {
"navigationBarTitleText": "供应端",
"enablePullDownRefresh": true
}
},
{
"path": "pages/supply/login/index",
"style": {
@ -12,13 +19,6 @@
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/supply/index/index",
"style": {
"navigationBarTitleText": "供应端",
"enablePullDownRefresh": true
}
},
{
"path": "pages/supply/offer/index",
"style": {
@ -111,6 +111,12 @@
"style": {
"navigationBarTitleText": "出库订单"
}
},
{
"path": "pages/empty/index",
"style": {
"navigationBarTitleText": "页面不存在"
}
}
],
"globalStyle": {

28
pages/empty/index.vue

@ -0,0 +1,28 @@
<template>
<view class="lf-row-center lf-flex-column lf-p-t-50">
<view class="lf-text-center">
<view class="lf-font-70" style="color: #e74c3c;">404</view>
<view class="lf-color-555 lf-font-28 lf-m-t-20">页面不存在</view>
</view>
</view>
</template>
<script>
export default {
data(){
return {
}
},
onLoad(){
},
methods: {
}
}
</script>
<style lang="scss" scoped="scoped">
</style>

66
pages/supply/index/index.vue

@ -1,40 +1,25 @@
<template>
<view>
<view class="lf-row-center lf-flex-column head">
<image src="../../../static/logo.png"></image>
<view class="lf-m-t-20 lf-font-32 lf-font-bold lf-color-black">广西美味餐厅供应链有限公司</view>
<image :src="supplier.logo"></image>
<view class="lf-m-t-20 lf-font-32 lf-font-bold lf-color-black">{{ supplier.subject_name }}</view>
</view>
<view class="list">
<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/supply/offer/index')">
<view class="lf-row-between list-item" hover-class="lf-opacity"
v-for="(item, index) in block_list" :key="index"
@click="$url(item.path)">
<view class="lf-row-center">
<image class="icon-img" src="../../../static/logo.png"></image>
<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">发起报价</text>
</view>
<view>
<u-icon name="arrow-right"></u-icon>
</view>
</view>
<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/supply/order/index')">
<view class="lf-row-center">
<image class="icon-img" src="../../../static/logo.png"></image>
<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">报价订单</text>
</view>
<view>
<u-icon name="arrow-right"></u-icon>
</view>
</view>
<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/supply/gonghuo/order')">
<view class="lf-row-center">
<image class="icon-img" src="../../../static/logo.png"></image>
<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">供货订单</text>
<image class="icon-img" :src="item.icon"></image>
<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">{{ item.name }}</text>
</view>
<view>
<u-icon name="arrow-right"></u-icon>
</view>
</view>
</view>
<view style="height: 170rpx;"></view>
<view class="btn-bottom exit">
<button class="lf-w-100" @click="$msg('敬请期待...')">退出登录</button>
<button class="lf-w-100" @click="loginOut">退出登录</button>
</view>
</view>
</template>
@ -43,14 +28,36 @@
export default {
data(){
return {
supplier: {},
block_list: []
}
},
onLoad(){
this.getData();
},
methods: {
// 退
loginOut(){
uni.showModal({
title: '温馨提示',
content: '确定退出登录吗?',
confirmColor: '#1833F2',
success: result => {
if(result.confirm){
uni.removeStorageSync('supply_token');
this.$redirectToLogin('您已退出登录, 即将跳转...');
}
}
})
},
//
getData(){
this.$http(this.API.API_SUPPLIER_INDEX).then(res => {
console.log("data", res);
this.supplier = res.data.supplier;
this.block_list = res.data.block;
});
}
}
}
</script>
@ -101,8 +108,11 @@
}
.exit{
padding: 0 32rpx;
bottom: 50rpx;
// bottom: 50rpx;
padding-top: 10rpx;
padding-bottom: 50rpx;
box-sizing: border-box;
background-color: #F6F6F6;
button{
background-color: #f0f0f0;
color: #777777;

37
pages/supply/login/index.vue

@ -8,13 +8,13 @@
<u-icon name="account-fill"></u-icon>
<text class="lf-m-l-10 lf-font-28 lf-color-333">登录账号</text>
</view>
<input class="input" :adjust-position="false" :auto-blur="true" placeholder="请输入账号" @focus="inputFocus(170)" @blur="is_focus = false" />
<input class="input" v-model="user_key" :adjust-position="false" :auto-blur="true" placeholder="请输入账号" @focus="inputFocus(170)" @blur="inputBlur" />
<!-- 密码 -->
<view class="lf-flex lf-m-b-10 lf-m-t-60">
<u-icon name="lock-fill"></u-icon>
<text class="lf-m-l-10 lf-font-28 lf-color-333">登录密码</text>
</view>
<input class="input" :adjust-position="false" :auto-blur="true" placeholder="请输入密码" :password="true" @focus="inputFocus(220)" @blur="is_focus = false" />
<input class="input" v-model="user_pw" :adjust-position="false" :auto-blur="true" placeholder="请输入密码" :password="true" @focus="inputFocus(220)" @blur="inputBlur" />
</view>
<view>
<!-- 登录按钮 -->
@ -26,18 +26,21 @@
</template>
<script>
let time = null;
export default {
data(){
return {
is_focus: false
is_focus: false,
user_key: '',
user_pw: ''
}
},
onLoad(options){
},
methods: {
inputFocus(scrollTop){
this.is_focus = true;
time = setTimeout(() => {
this.is_focus = true;
}, 0); // blur
setTimeout(() => {
uni.pageScrollTo({
scrollTop: scrollTop,
@ -45,8 +48,26 @@
})
}, 200);
},
inputBlur(){
time = setTimeout(() => {
this.is_focus = false;
}, 0); // click
},
login(){
this.$url('/pages/supply/index/index');
if(!this.user_key){
this.$msg('账号不能为空');
}else if(!this.user_pw){
this.$msg('密码不能为空');
}else{
this.$http(this.API.API_SUPPLIER_LOGIN, {
username: this.user_key,
password: this.user_pw
}).then(res => {
console.log("login", res);
uni.setStorageSync('supply_token', res.data.token);
this.$url('/pages/supply/index/index');
})
}
}
}
}

Loading…
Cancel
Save