Commit 80a45971 by zhangpeng

搭建框架

parent 18ae5f8f
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
</style>
<script>
export default {
onLaunch: function() {
console.log('App Launch')
// uni.showLoading({
// title: '加载中...',
// mask:true
// });
// uni.clearStorageSync();
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods:{
unilogin(){
}
}
}
</script>
<style lang="scss">
<style>
/*每个页面公共css */
@import "uview-ui/index.scss";
</style>
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
import App from './App'
import uView from 'uview-ui';
Vue.use(uView);
//引入vuex
import store from './store'
import utils from './utils/utils'
Vue.prototype.$utils = utils
// console.log(Vue.$u,22)
// 需要在Vue.use(uView)之后执行
uni.$u.setConfig({
// 修改$u.config对象的属性
config: {
// 修改默认单位为rpx,相当于执行 uni.$u.config.unit = 'rpx'
unit: 'rpx'
},
// 修改$u.props对象的属性
// props: {
// // 修改radio组件的size参数的默认值,相当于执行 uni.$u.props.radio.size = 30
// radio: {
// size: 15
// }
// // 其他组件属性配置
// // ......
// }
})
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
......@@ -29,6 +17,7 @@ const app = new Vue({
store
})
app.$mount()
require('./request/index')(app);
// #endif
// #ifdef VUE3
......
......@@ -50,9 +50,12 @@
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "",
"appid" : "wxdb0df0ee46a184be",
"setting" : {
"urlCheck" : false
"urlCheck" : false,
"es6" : false,
"postcss" : true,
"minified" : true
},
"usingComponents" : true
},
......
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
{}
\ No newline at end of file
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
{}
\ No newline at end of file
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
\ No newline at end of file
{}
\ No newline at end of file
......@@ -3,6 +3,12 @@
},
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": ""
}
}
,{
"path" : "pages/menu/menu",
"style" :
{
......@@ -11,14 +17,7 @@
"enablePullDownRefresh": false
}
},
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": ""
}
}
,{
},{
"path" : "pages/order/order",
"style" :
{
......@@ -38,11 +37,58 @@
}
],
"subPackages": [
{
"root": "menuSubPackage",
"pages": [
{
"path": "pages/demo/demo",
"style": {
// "navigationBarBackgroundColor": "",
// "navigationBarTitleText": "",
"enablePullDownRefresh": false
// "navigationStyle":"custom"
}
}
]
},
{
"root": "orderSubPackage",
"pages": [
{
"path": "pages/demo/demo",
"style": {
// "navigationBarBackgroundColor": "",
// "navigationBarTitleText": "",
"enablePullDownRefresh": false
// "navigationStyle":"custom"
}
}
]
},
{
"root": "mineSubPackage",
"pages": [
{
"path": "pages/demo/demo",
"style": {
// "navigationBarBackgroundColor": "",
// "navigationBarTitleText": "",
"enablePullDownRefresh": false
// "navigationStyle":"custom"
}
}
]
}
],
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "HOOLOO",
"navigationBarBackgroundColor": "#2A9BD1",
"backgroundColor": "#F8F8F8"
"navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#ffffff"
},
"tabBar": {
"custom":true,
......
<template>
<u-button>分导页</u-button></u-button>
<view class="content">
</view>
</template>
<script>
export default {
}
import config from '../../static/config/index.js'
import Order from '../../request/order/index'
export default {
data() {
return {
id:''
}
},
onLoad(options) {
this.id='';
this.$store.commit('setOrderId','');
if(options.q){
let url=decodeURIComponent(options.q);
this.id=url.split('/')[url.split('/').length-1];
this.$store.commit('setOrderId',this.id);
}
},
async onShow() {
// let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
// let curRoute = routes[routes.length - 1].route //获取当前页面路由
//   let curParam = routes[routes.length - 1].options;
//  console.log(curParam)
let user=uni.getStorageSync(`currentUser`);
if(user){ //
user=await JSON.parse(user);
if(user.realName){ //有说明授权登陆过
this.checkSession();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
}else{
uni.clearStorageSync();
uni.reLaunch({
url:'/pages/menu/menu'
})
}
},
methods: {
// 登录
login(){
this.$utils.uniLogin().then(async user => {
this.$store.commit('setUserInfo',user);
if(!user.realName){
uni.reLaunch({
url:'/pages/menu/menu'
})
}else{
if(this.id!=''){//二维码参数
this.valiFrequency();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
}
}).catch((err)=>{
uni.showToast({
icon:'none',
title:'登录失败'
})
});
},
// 校验
async valiFrequency() {//去订单查看是否有此订单
let order=await Order.valiFrequency(this.id);
if(!order){
//无此订单
// uni.navigateTo({
// url:`/pages/detail/detail?id=${this.id}`
// })
}else{
// uni.navigateTo({
// url:`/pages/detail/detail?id=${this.id}`
// });
//是订单跳转到详情页或者其他相关页面
}
},
// sessionkey校验登陆状态
checkSession(){
uni.checkSession({
success:(res)=>{
let user=uni.getStorageSync(`currentUser`);
this.$store.commit('setUserInfo',user);
if(this.id!=''){//二维码参数
this.valiFrequency();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
},
fail:(res)=>{
uni.clearStorageSync();
this.login();
}
});
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
</style>
\ No newline at end of file
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
<template>
<view>
我的页面
<!-- Tab -->
<u-tabbar v-model="selectedTabbar" :border="false" inactive-color="#000000" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch">
<u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item>
</u-tabbar>
</view>
</template>
......@@ -8,11 +11,20 @@
export default {
data() {
return {
selectedTabbar:2,//选中的tab
}
},
computed:{
list(){
// tabbar List
return this.$store.state.list;
}
},
methods: {
beforeSwitch(index) {
uni.switchTab({url:this.list[index].pagePath});
return true;
}
}
}
</script>
......
<template>
<view>
<!-- Tab -->
<u-tabbar v-model="selectedTabbar" :border="false" inactive-color="#000000" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch">
<u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item>
</u-tabbar>
</view>
</template>
<script>
export default {
name:'order',
data() {
return {
selectedTabbar:1,//选中的tab
}
},
computed:{
list(){
// tabbar List
return this.$store.state.list;
}
},
methods: {
beforeSwitch(index) {
uni.switchTab({url:this.list[index].pagePath});
return true;
}
}
}
</script>
......
import appConfig from '@/static/config/index.js';
export function getBaseUrl() {
if (process.env.NODE_ENV === 'development') {
console.log(121)
return appConfig.devApi;
} else {
return appConfig.prodApi;
}
}
module.exports = (vm) => {
console.log(vm.$store)
uni.$u.http.setConfig((config) => {
config.baseURL= getBaseUrl();
// showLoading: process.env.NODE_ENV === 'development',
config.method= 'POST';
// 设置为json,返回后会对数据进行一次JSON.parse()
config.dataType = 'json';
config.timeout = 3000; // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
// 配置请求头信息
config.header= {
'Content-Type': 'application/json' // 'application/x-www-form-urlencoded'
}
return config;
});
// 请求拦截
uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
uni.showLoading({
title: '加载中',
mask: true,
});
let user = uni.getStorageSync(`currentUser`);
let token = undefined;
if(user){
token = JSON.parse(user).sessionToken;
if (token){
config.header.token = token;
}
}
if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
// return Promise.reject(config);
}
return config
}, config => { // 可使用async await 做异步操作
return Promise.reject(config)
});
// 响应拦截
uni.$u.http.interceptors.response.use((response) => {
uni.hideLoading();
/* 对响应成功做点什么 可使用async await 做异步操作*/
if (response.data.code !== 200) { // 服务端返回的状态码不等于200,则reject()
uni.showToast({
title: response.data.msg,
icon: 'none',
duration: 2000
})
return Promise.reject(response)
} // return Promise.reject 可使promise状态进入catch
console.log(response)
return response
}, (response) => {
uni.hideLoading();
/* 对响应错误做点什么 (statusCode !== 200)*/
console.log(response)
return Promise.reject(response)
});
}
\ No newline at end of file
export default {
// 获取菜单列表
getMenuList(id) {
uni.$u.http.get('/erer/erer',{
params:{
}
}).then(res => {
}).catch(err => {
})
},
// 下单获取预支付订单
saveReserve() {
uni.$u.http.post('/erer/erer', {
}).then(res => {
}).catch(err => {
})
},
// saveReserve 为业务接口
requestPayment(data) {
const {
errno,
errmsg,
res
} = data;
// res为调起微信支付所需参数
if (errno === '0') {
// 调起微信支付
uni.requestPayment({
provider: 'wxpay', // 服务提提供商微信支付
timeStamp: res.weChatPayData.timestamp, // 时间戳
nonceStr: res.weChatPayData.noncestr, // 随机字符串
package: res.weChatPayData.package,
signType: res.weChatPayData.signtype || 'MD5', // 签名算法
paySign: res.weChatPayData.sign, // 签名
success: function (res) {
console.log('支付成功', res);
// 业务逻辑。。。
},
fail: function (err) {
console.log('支付失败', err);
}
});
}
}
}
\ No newline at end of file
export default {
getList(id) {
}
}
\ No newline at end of file
export default{
valiFrequency(id) {
}
}
\ No newline at end of file
......@@ -26,7 +26,8 @@ const store = new Vuex.Store({
}
],
userInfo:{},//授权信息
authorization:false//是否授权
authorization:false,//是否授权
orderId:''//外部扫码进入的商品id
},
mutations: {
// 设置是否授权
......@@ -36,6 +37,10 @@ const store = new Vuex.Store({
// 设置用户信息
setUserInfo(state,userInfo){
state.userInfo=userInfo;
},
// 设置扫码进入的商品id
setOrderId(state, orderId) {
state.orderId = orderId;
}
},
actions: {}
......
......@@ -5,17 +5,21 @@ export default{
uni.login({
provider: 'weixin',
success: function (loginRes) {
return loginRes.code;
console.log(loginRes)
}})
},
async uniGetUserInfo() {
uni.getUserInfo({
provider: 'weixin',
success: function (infoRes) {
let username=infoRes.userInfo.nickName;//用户名
let gender=infoRes.userInfo.gender;//用户性别
let avatarUrl=infoRes.userInfo.avatarUrl;//头像
}})
async uniGetUserInfo(e) {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息
lang: "zh_CN",
desc: '用于完善用户信息',
success: res => {
let avatarUrl = res.userInfo.avatarUrl;
let nickName = res.userInfo.nickName;
console.log(res)
this.uniLogin();
}
})
},
// 解密手机
async onGetPhoneNumber(appid,session_key,encryptedData,iv) {
......@@ -72,56 +76,6 @@ export default{
" " + hours + ":" + minutes;
return time;
},
// 校验营养输入输入框
async validNum(YYTJ,finaly) {
let res=true;
let YYFL={EN:'EN',PNAJS:'PN氨基酸',PNZFRJ:'PN脂肪乳剂',DQDQHY:'多腔袋全合一'};
for(let i=0;i<YYTJ.length;i++){
let item=YYTJ[i];
let index=item.med.index;
index=YYFL[index]||'';
if(item.dose!==''&&isNaN(item.dose)){
if(finaly){
uni.showToast({
title:`${index}:请输入正确的数值`,
icon:'none'
});
res=false;
break;
}else if(!finaly){
uni.showToast({
title:`${index}:请输入正确的数值`,
icon:'none'
});
}
}else if(finaly&&item.med.name==''&&item.dose!==''&&!isNaN(item.dose)){
uni.showToast({
title:`${index}:请选择药剂名称`,
icon:'none'
});
res=false;
break;
}
}
return res;
},
//过滤营养输入的方法
filterYYTJ(sourceForm){
let YYMC=['EN','PNAJS','PNZFRJ','DQDQHY'];
let form=JSON.parse(JSON.stringify(sourceForm));
YYMC.forEach(v=>{
form[v]=form[v].filter(item=>{
if(item.dose==''){
item.dose=0;
}else{
item.dose=Number(item.dose)
}
return item.med.name!=''
});
}
);
return form;
},
numberFixed(data,fixed=2){
if(data==undefined){
return undefined
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment