Commit c60cd8ab by LiuJunYi

我的模块

parents c96013bd 133e2d7c
......@@ -22,139 +22,18 @@ App({
*/
checkUserLogin: function(callback) {
let _app = this
if (_app.globalData.userInfo == null) {
_app.requestWxLogin(function(res) {
typeof callback == "function" && callback()
if (_app.globalData.userInfo == null || !wx.getStorageSync('token')) {
wx.navigateTo({
url: '/pages/auth/index',
})
} else {
console.log("用户已登录", _app.globalData.userInfo)
typeof callback == "function" && callback()
api.me.info().then(res => {
console.log(res)
})
}
},
/**
* 请求微信授权登陆
*/
requestWxLogin: function(callback) {
let that = this
wx.login({
success: function(res) {
if (res.code) {
//发起网络请求
let wxcode = res.code
wx.getUserInfo({
withCredentials: true,
lang: 'zh_CN',
success: function(data) {
console.info("1成功获取用户返回数据", wxcode, data);
that.requestServerLogin(wxcode, data, callback)
},
fail: function() {
console.info("1授权失败返回数据");
// 显示提示弹窗
wx.showModal({
title: '授权失败',
content: '你的微信授权未开启,将无法使用小程序!',
success: function(res) {
if (res.confirm) {
wx.openSetting({
success: function(data) {
if (data && data.authSetting["scope.userInfo"] == true) {
wx.getUserInfo({
withCredentials: true,
success: function(data) {
console.info("3成功获取用户返回数据");
that.requestServerLogin(wxcode, data, callback)
},
fail: function() {
console.info("3授权失败返回数据");
}
});
}
},
fail: function() {
console.info("设置失败返回数据");
}
});
} else if (res.cancel) {
console.log('用户坚持取消授权')
}
}
});
}
});
}
},
fail: function() {
console.info("登录失败返回数据");
}
});
},
/**
* 请求获取群id openGid 所需参数
*/
requestShareTicket: function(callback) {
let that = this
wx.login({
success: function(res) {
let wxcode = res.code
wx.getShareInfo({
shareTicket: that.options.shareTicket,
success: function(res) {
that.requestServerWithShareData(wxcode, {
encryptedData: res.encryptedData,
iv: res.iv
}, callback)
}
})
}
})
},
/**
* 请求服务器登陆
*/
requestServerLogin: function(wxcode, data, callback) {
let _app = this
api.login({
code: wxcode,
signature: data.signature,
rawData: data.rawData,
encryptedData: data.encryptedData,
iv: data.iv,
scene: _app.options.query && _app.options.query.scene ? decodeURIComponent(_app.options.query.scene) : ''
}).then(res => {
if (!res.code) {
_app.globalData.userInfo = res.user
_app.globalData.token = res.token
typeof callback == "function" && callback(res.user)
}
if (_app.options.scene == 1044 && _app.options.shareTicket) {
_app.requestShareTicket(function(ret) {
console.log("Request Share Ticket", ret)
})
}
})
},
/**
* 请求服务器解析数据获取 openGid
*/
requestServerWithShareData(wxcode, data, callback) {
let _app = this
api.shareTicket({
token: _app.globalData.token,
code: wxcode,
encryptedData: data.encryptedData,
iv: data.iv
}).then(res => res.data).then(res => {
typeof callback == "function" && callback(res)
})
},
globalData: {
userInfo: null,
token: ''
userInfo: null
}
})
\ No newline at end of file
/**app.wxss**/
page{
background: #f5f5f5;
}
.container {
height: 100%;
display: flex;
......@@ -10,33 +12,6 @@
box-sizing: border-box;
}
/* 用于收集 formid 的 button 样式 */
button.form-button {
background-color: transparent;
padding: 0;
margin: 0;
display: inline;
position: static;
border: 0;
padding-left: 0;
padding-right: 0;
border-radius: 0;
font-size: 0;
text-align: left;
line-height: normal;
}
button.form-button::after {
content: '';
width: 0;
height: 0;
-webkit-transform: scale(1);
transform: scale(1);
display: none;
background-color: transparent;
}
.text-gray {
color: rgb(191, 191, 191);
}
......
const Util = require('../utils/Util.js')
const app = getApp()
import api from '../utils/Api.js'
module.exports = Behavior({
behaviors: [],
......@@ -7,26 +6,24 @@ module.exports = Behavior({
data: {
formApi: 'user/save_formid'
},
attached: function () { },
attached: function() {},
methods: {
/**
* 绑定页面中收集 formId 的 submit 事件
*/
__collectFormId: function (event) {
__collectFormId: function(event) {
let formId = event.detail.formId
let token = app.globalData ? app.globalData.token : ''
this.__postFormId(formId, token)
this.__postFormId(formId)
},
/**
* 提交 formId 到服务器
*/
__postFormId: function (formId, token) {
__postFormId: function(formId) {
let that = this
app.requestData(that.data.formApi, Util.sign({
token: token,
api.saveFormId({
formid: formId
}), 'POST', function (res) {
}).then(res => {
console.log('colletion formid: ', res)
})
}
......
const Util = require('../utils/Util.js')
const app = getApp()
import api from '../utils/Api.js'
module.exports = Behavior({
behaviors: [],
properties: {},
data: {},
attached: function () { },
attached: function() {},
methods: {
/**
* 获取手机号按钮回调事件
*/
__getPhoneNumber: function (event, callback) {
__getPhoneNumber: function(event, callback) {
let that = this
wx.login({
success: function (res) {
success: function(res) {
let encryptedData = event.detail.encryptedData
let iv = event.detail.iv
that.__decodePhoneData(res.code, encryptedData, iv, function (res) {
that.__decodePhoneData(res.code, encryptedData, iv, function(res) {
typeof callback == "function" && callback(res)
})
}
})
},
/**
* 解密用户数据
*/
__decodePhoneData: function (code, encryptedData, iv, callback) {
__decodePhoneData: function(code, encryptedData, iv, callback) {
let that = this
app.requestData('user/auth_phone', Util.sign({
token: app.globalData.token,
api.getPhoneNumber({
code: code,
encryptedData: encryptedData,
iv: iv
}), 'POST', function (res) {
}).then(res => {
if (!res.code) {
typeof callback == "function" && callback(res)
} else {
app.showToastWithImg('授权失败')
wx.showToast({
title: '授权失败'
})
}
})
}
......
// components/search-filter/index.js
import api from '../../utils/Api.js'
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
types: [],
catalogs: [],
regions: [],
tags: [],
filter_idx:0
},
/**
* 组件渲染完后的方法
*/
ready(){
api.search.filter().then(res=>{
this.setData({
types: res.data.type,
catalogs: res.data.catalog_id,
regions: res.data.city,
tags: res.data.tags
})
})
},
/**
* 组件的方法列表
*/
methods: {
filterTap: function (event){
let idx = event.target.dataset.idx;
if(idx==this.data.filter_idx){
this.setData({ filter_idx: 0 })
}else{
this.setData({ filter_idx: idx })
}
if(idx==1){
} else if (idx == 2) {
}
var myEventDetail = {test:"helloworld"} // detail对象,提供给事件监听函数
var myEventOption = {} // 触发事件的选项
this.triggerEvent('change', myEventDetail, myEventOption)
},
closeFilter: function(event){
this.setData({ filter_idx: 0 })
},
preventEvent: function (event) {
}
}
})
{
"component": true,
"usingComponents": {
"i-row": "/iview/row/index",
"i-col": "/iview/col/index"
}
}
\ No newline at end of file
<!--components/search-filter/index.wxml-->
<view class='filter-wrapper'>
<i-row i-class='row-filter'>
<i-col span="6">
<view class="filter-item">
<text class="{{filter_idx==1?'active':''}}" catchtap='filterTap' data-idx="1">全部项目</text>
<image class="search-icon" src="/images/icon-down-select{{filter_idx==1?'ed':''}}.png"></image>
</view>
</i-col>
<i-col span="6" i-class="col-class">
<view class="filter-item">
<text class="{{filter_idx==2?'active':''}}" catchtap='filterTap' data-idx="2">分类</text>
<image class="search-icon" src="/images/icon-down-select{{filter_idx==2?'ed':''}}.png"></image>
</view>
</i-col>
<i-col span="6" i-class="col-class">
<view class="filter-item">
<text class="{{filter_idx==3?'active':''}}" catchtap='filterTap' data-idx="3">地域</text>
<image class="search-icon" src="/images/icon-down-select{{filter_idx==3?'ed':''}}.png"></image>
</view>
</i-col>
<i-col span="6" i-class="col-class">
<view class="filter-item">
<text class="{{filter_idx==4?'active':''}}" catchtap='filterTap' data-idx="4">标签</text>
<image class="search-icon" src="/images/icon-down-select{{filter_idx==4?'ed':''}}.png"></image>
</view>
</i-col>
</i-row>
<view catchtap='closeFilter' class='filter-content-wrapper' wx:if="{{filter_idx>0}}">
<view class="row-content" catchtap='preventEvent'>
<view wx:if="{{filter_idx==1}}" class='filter-row' wx:for="{{types}}" wx:for-index="idx" wx:for-item="n" wx:key="n.id">
<text>{{n.name}}</text>
<image class='f-selected' src='/images/icon_filter_selected.png'></image>
</view>
<view wx:if="{{filter_idx==2}}" class='filter-row' wx:for="{{catalogs}}" wx:for-index="idx" wx:for-item="n" wx:key="n.id">
<text>{{n.name}}</text>
<image class='f-selected' src='/images/icon_filter_selected.png'></image>
</view>
<view wx:if="{{filter_idx==3}}" class='filter-row' wx:for="{{regions}}" wx:for-index="idx" wx:for-item="n" wx:key="n.id">
<text>{{n.name}}</text>
<image class='f-selected' src='/images/icon_filter_selected.png'></image>
</view>
<view class="tags-wrapper" wx:if="{{filter_idx==4}}">
<view class="tag-item {{n.selected==1?'active':''}}" wx:for="{{tags}}" wx:for-index="idx" wx:for-item="n" wx:key="n.id">
{{n.name}}
</view>
<view class="tag-btn-wrapper">
<button class="btn cancel">取消选择</button>
<button class="btn ensure">确定</button>
</view>
</view>
</view>
</view>
</view>
\ No newline at end of file
/* components/search-filter/index.wxss */
.filter-wrapper {
position: relative;
width: 100%;
}
.row-filter {
height: 56px;
line-height: 56px;
}
.filter-item {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.filter-item > image {
width: 12rpx;
height: 10rpx;
margin-left: 12rpx;
}
.filter-item > text {
color: rgb(51, 51, 51);
font-size: 28rpx;
}
.filter-item > text.active {
color: rgb(43, 163, 215);
}
.filter-content-wrapper {
position: fixed;
width: 100%;
top: 96px;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.3);
}
.row-content {
position: relative;
border-top: 1px solid #f4f4f4;
background: white;
width: 100%;
padding: 34rpx 30rpx;
padding-right: 50rpx;
box-sizing: border-box;
}
.filter-row {
width: 100%;
display: flex;
align-items: center;
box-sizing: border-box;
justify-content: space-between;
font-size: 28rpx;
color: rgb(191, 191, 191);
margin-bottom: 46rpx;
}
.filter-row:last-child {
margin-bottom: 0rpx;
}
.filter-row > .f-selected {
height: 27rpx;
width: 23rpx;
}
.tags-wrapper {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
align-items: center;
}
.tag-item {
min-width: 120rpx;
padding: 0 10rpx 0 10rpx;
height: 75rpx;
border: 1px solid #f4f4f4;
color: rgb(102, 102, 102);
font-size: 26rpx;
display: flex;
align-items: center;
justify-content: center;
margin: 10rpx;
border-radius: 2rpx;
}
.tag-btn-wrapper {
display: block;
width: 100%;
margin-top: 30rpx;
text-align: center;
}
.tag-btn-wrapper > button.btn {
display: inline-block;
background: none;
font-size: 14px;
height: 60rpx;
border-radius: 30rpx;
line-height: 60rpx;
outline-style: none;
}
.tag-btn-wrapper > button.cancel {
border: 1px solid #eee;
color: rgb(102, 102, 102);
margin-right: 30rpx;
}
.tag-btn-wrapper > button.ensure {
border: 1px solid rgb(43, 163, 215);
color: rgb(43, 163, 215);
}
// pages/auth/index.js
Page({
import Wx from '../../utils/Wx.js'
import api from '../../utils/Api.js'
const {
$Toast
} = require('../../iview/base/index');
const app = getApp()
Page({
/**
* 页面的初始数据
*/
......@@ -11,56 +17,93 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onShow: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
handleWxAuth: function(event) {
Wx.login().then(res => {
api.login({
code: res.code,
signature: event.detail.signature,
rawData: event.detail.rawData,
encryptedData: event.detail.encryptedData,
iv: event.detail.iv,
scene: app.options.query && app.options.query.scene ? decodeURIComponent(app.options.query.scene) : ''
}).then(res => {
if (!res.code) {
app.globalData.userInfo = res.user
wx.setStorage({
key: 'token',
data: res.token,
})
Wx.showToast({
title: '微信授权成功',
icon: 'success',
duration: 2000,
}).then(() => {
wx.navigateBack({
delta: 1
})
})
} else {
$Toast({
content: '微信授权失败,请重试',
type: 'error'
});
}
})
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
handlePhoneAuth: function(event) {
Wx.login().then(res => {
let encryptedData = event.detail.encryptedData
let iv = event.detail.iv
this.decodePhoneData(res.code, encryptedData, iv)
})
},
/**
* 用户点击右上角分享
* 解密用户数据
*/
onShareAppMessage: function () {
decodePhoneData: function(code, encryptedData, iv) {
let that = this
api.getPhoneNumber({
code: code,
encryptedData: encryptedData,
iv: iv
}).then(res => {
if (!res.code) {
$Toast({
content: '手机号授权成功',
type: 'success'
});
let userInfo = app.globalData.userInfo
app.globalData.userInfo = {
...userInfo,
...res.data
}
} else {
$Toast({
content: '手机号授权失败',
type: 'error'
});
}
})
}
})
\ No newline at end of file
{}
\ No newline at end of file
{
"navigationBarTitleText": "微信授权",
"usingComponents": {
"i-button": "/iview/button/index",
"i-toast": "/iview/toast/index"
}
}
\ No newline at end of file
<!--pages/auth/index.wxml-->
<text>pages/auth/index.wxml</text>
<view class='v-page'>
<view class='container'>
<image class='logo' src='/images/icon_location.png' mode='scaleToFill'></image>
<view class='slogan'>
<view>没行者亲子游</view>
<view>美好的教育,行走在路上</view>
</view>
<view class='action-wrapper'>
<i-button bindgetuserinfo="handleWxAuth" type="success" shape="circle" open-type='getUserInfo'>微信授权</i-button>
<i-button bindgetphonenumber="handlePhoneAuth" type="info" shape="circle" open-type="getPhoneNumber">手机号授权</i-button>
<view class="text-small text-hint tip">请完成2步,微信授权</view>
</view>
</view>
</view>
<i-toast id="toast" />
\ No newline at end of file
/* pages/auth/index.wxss */
\ No newline at end of file
/* pages/auth/index.wxss */
page {
position: relative;
background: #fff;
height: 100%;
}
.v-page {
position: relative;
height: 100%;
}
.container {
position: relative;
display: flex;
flex-direction: column;
align-content: center;
align-items: center;
}
.logo {
width: 68%;
}
.slogan {
text-align: center;
width: 100%;
color: #767676;
font-size: 16px;
margin-top: 30px;
margin-bottom: 40px;
line-height: 24px;
}
.action-wrapper {
width: 100%;
padding: 0 40px;
box-sizing: border-box;
}
.action-wrapper .tip {
text-align: center;
}
/* pages/guide/index.wxss */
\ No newline at end of file
/* pages/guide/index.wxss */
......@@ -75,9 +75,7 @@ Page({
},
getHomeData: function(callback) {
api.home.all({
token: app.globalData.token
}).then(res => {
api.home.all().then(res => {
this.setData({
news: res.data.newProjects,
heats: res.data.heatProjects,
......
......@@ -3,7 +3,9 @@
"backgroundColor": "#f5f5f5",
"usingComponents": {
"i-avatar": "/iview/avatar/index",
"i-cell-group": "/iview/cell-group/index",
"i-cell": "/iview/cell/index"
"i-cell-group": "/iview/cell-group/index",
"i-cell": "/iview/cell/index",
"i-row": "/iview/row/index",
"i-col": "/iview/col/index"
}
}
\ No newline at end of file
......@@ -17,29 +17,33 @@
<i-cell title="我的订单" is-link url="/pages/dashboard/index">
<text slot="footer" class='text-gray'>全部</text>
</i-cell>
<view class='order-status-box'>
<view class='order-items'>
<i-row i-class="order-status-box">
<i-col span="8" i-class="col-class">
<view class='order-item'>
<image src='/images/personal_center/icon_be_in_progress.png'></image>
<text>进行中</text>
</view>
</i-col>
<i-col span="8" i-class="col-class">
<view class='order-item'>
<image src='/images/personal_center/icon_to_be_evaluated.png'></image>
<text>待评价</text>
</view>
</i-col>
<i-col span="8" i-class="col-class">
<view class='order-item'>
<image src='/images/personal_center/icon_completed.png'></image>
<text>已完成</text>
</view>
</view>
</view>
</i-col>
</i-row>
</i-cell-group>
<i-cell-group i-class='vip'>
<i-cell title="VIP会员" is-link url="/pages/dashboard/index">
<text slot="footer" class='text-gray'>全部</text>
</i-cell>
<i-cell title="我的收藏" is-link url="/pages/dashboard/index"></i-cell>
<i-cell title="我的收藏" is-link url="/pages/collection/index"></i-cell>
</i-cell-group>
<i-cell-group>
......
......@@ -35,7 +35,7 @@ page {
transform: translateX(-50%);
}
.avatar_box>image {
.avatar_box > image {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
......@@ -50,7 +50,7 @@ page {
align-items: center;
}
.user-info-box>text {
.user-info-box > text {
color: #fff;
font-size: 30rpx;
}
......@@ -65,20 +65,11 @@ page {
.order-status-box {
background-color: #fff;
height: 182rpx;
padding: 20px 0;
margin-bottom: 20rpx;
width: 100%;
}
.order-items {
background-color: #fff;
padding: 32rpx 0 0 0;
margin: auto;
display: flex;
width: 480rpx;
justify-content: space-between;
}
.order-item {
display: flex;
flex-direction: column;
......@@ -90,8 +81,8 @@ page {
}
.order-item > image {
width: 40rpx;
height: 44rpx;
width: 48rpx;
height: 48rpx;
}
.vip {
......
......@@ -62,5 +62,9 @@ Page({
*/
onShareAppMessage: function () {
},
filterChange: function (event){
console.log(event)
}
})
\ No newline at end of file
{}
\ No newline at end of file
{
"navigationBarTitleText": "搜索",
"usingComponents": {
"search-filter": "/components/search-filter/index"
}
}
\ No newline at end of file
<!--pages/search/index.wxml-->
<text>pages/search/index.wxml</text>
<view class="page-wrapper">
<view class='search-wrapper'>
<image class="search-icon" src='/images/icon_search.png'></image>
<view class='search-input'>关键词如地名、游泳等</view>
</view>
<search-filter bind:change="filterChange" />
</view>
\ No newline at end of file
/* pages/search/index.wxss */
\ No newline at end of file
/* pages/search/index.wxss */
.page-wrapper{
background: white;
}
.search-wrapper{
display: flex;
justify-content: flex-start;
align-items: center;
margin: 0px 30rpx;
background: rgb(247, 247, 247);
box-sizing: border-box;
border: 4rpx;
height: 40px;
padding-left: 20rpx;
}
.search-icon{
width: 31rpx;
height: 31rpx;
}
.search-input{
font-size: 26rpx;
color: rgb(153, 153, 153);
padding-left: 10rpx;
}
.search-input:-moz-placeholder, .search-input:-ms-input-placeholder, .search-input::-webkit-input-placeholder{
color: rgb(153, 153, 153);
}
......@@ -37,7 +37,11 @@
"list": []
},
"miniprogram": {
<<<<<<< HEAD
"current": 3,
=======
"current": 4,
>>>>>>> 133e2d7cbbbda20f7e1a885855a832728002329a
"list": [
{
"id": 0,
......@@ -59,8 +63,20 @@
},
{
"id": -1,
<<<<<<< HEAD
"name": "vip",
"pathName": "pages/me/vip/index"
=======
"name": "搜索",
"pathName": "pages/search/index",
"query": ""
},
{
"id": 4,
"name": "授权",
"pathName": "pages/auth/index",
"query": ""
>>>>>>> 133e2d7cbbbda20f7e1a885855a832728002329a
}
]
}
......
......@@ -14,6 +14,10 @@ export const shareTicket = params => {
return req.post('user/get_groupid', params).then(res => res.data)
}
export const getPhoneNumber = params => {
return req.post('user/getPhoneNumber', params).then(res => res.data)
}
export const home = {
banner: params => {
return req.post('banner/index', params).then(res => res.data)
......@@ -50,9 +54,25 @@ export const me = {
}
}
export const search = {
index: params => {
return req.post('project/index', params).then(res => res.data)
},
filter: params => {
return req.post('project/searchCondition', params).then(res => res.data)
}
}
export const saveFormId = params => {
return req.post('user/save_formid', params).then(res => res.data)
}
export default {
login,
shareTicket,
getPhoneNumber,
home,
guide
guide,
search,
saveFormId
}
\ No newline at end of file
......@@ -62,7 +62,10 @@ class Request {
url,
method: METHOD.POST,
header,
data: Util.sign(data)
data: Util.sign({
...data,
token: wx.getStorageSync('token')
})
})
}
put(url, data, header) {
......
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