商城下单购买,品类接口,钱包依赖

This commit is contained in:
唐明明
2022-01-07 16:28:29 +08:00
parent 6d4971bc5e
commit a75b9e7964
20 changed files with 1176 additions and 69 deletions

View File

@@ -15,21 +15,49 @@ const mall = () =>{
}
// 商品详情
const goods = (id) => {
const goods = id => {
return request({
url: 'mall/goods/' + id
})
}
// 套餐列表
const meals = (id) => {
const meals = id => {
return request({
url: 'mall/meals/' + id
})
}
// 商品列表
const lists = data => {
return request({
url: 'mall/goods',
data
})
}
// 确认订单
const buy = data => {
return request({
url: 'mall/buy/goods',
data
})
}
// 商品下单
const verify = data => {
return request({
url: 'mall/buy/goods',
method: 'POST',
data
})
}
export {
mall,
goods,
meals
meals,
lists,
buy,
verify
}

181
package-lock.json generated
View File

@@ -2,6 +2,182 @@
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"base-x": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz",
"integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"bech32": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz",
"integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg=="
},
"bigi": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
"integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU="
},
"bip-schnorr": {
"version": "0.6.4",
"resolved": "https://registry.npmjs.org/bip-schnorr/-/bip-schnorr-0.6.4.tgz",
"integrity": "sha512-dNKw7Lea8B0wMIN4OjEmOk/Z5qUGqoPDY0P2QttLqGk1hmDPytLWW8PR5Pb6Vxy6CprcdEgfJpOjUu+ONQveyg==",
"requires": {
"bigi": "^1.4.2",
"ecurve": "^1.0.6",
"js-sha256": "^0.9.0",
"randombytes": "^2.1.0",
"safe-buffer": "^5.2.1"
}
},
"bitcore-lib": {
"version": "8.25.25",
"resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-8.25.25.tgz",
"integrity": "sha512-H6qNCVl4M8/MglXhvc04mmeus1d6nrmqTJGQ+xezJLvL7hs7R3dyBPtOqSP3YSw0iq/GWspMd8f5OOlyXVipJQ==",
"requires": {
"bech32": "=2.0.0",
"bip-schnorr": "=0.6.4",
"bn.js": "=4.11.8",
"bs58": "^4.0.1",
"buffer-compare": "=1.1.1",
"elliptic": "^6.5.3",
"inherits": "=2.0.1",
"lodash": "^4.17.20"
}
},
"bitcore-mnemonic": {
"version": "8.25.25",
"resolved": "https://registry.npmjs.org/bitcore-mnemonic/-/bitcore-mnemonic-8.25.25.tgz",
"integrity": "sha512-7HvRxHrmd+Rh0Ohl0SEDMKQBAM+FoevXbCFnxGju6H+uZjtWMOToHA8vUg0+B91pfEMjdt9mQVB/wSA8GMqnCA==",
"requires": {
"bitcore-lib": "^8.25.25",
"unorm": "^1.4.1"
}
},
"bn.js": {
"version": "4.11.8",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
"integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
},
"brorand": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz",
"integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8="
},
"bs58": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz",
"integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=",
"requires": {
"base-x": "^3.0.2"
}
},
"buffer-compare": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-compare/-/buffer-compare-1.1.1.tgz",
"integrity": "sha1-W+e+hTr4kZjR9N3AkNHWakiu9ZY="
},
"ecurve": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz",
"integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==",
"requires": {
"bigi": "^1.1.0",
"safe-buffer": "^5.0.1"
}
},
"elliptic": {
"version": "6.5.4",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
"integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==",
"requires": {
"bn.js": "^4.11.9",
"brorand": "^1.1.0",
"hash.js": "^1.0.0",
"hmac-drbg": "^1.0.1",
"inherits": "^2.0.4",
"minimalistic-assert": "^1.0.1",
"minimalistic-crypto-utils": "^1.0.1"
},
"dependencies": {
"bn.js": {
"version": "4.12.0",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
"integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
}
}
},
"hash.js": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz",
"integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==",
"requires": {
"inherits": "^2.0.3",
"minimalistic-assert": "^1.0.1"
},
"dependencies": {
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
}
}
},
"hmac-drbg": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
"integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=",
"requires": {
"hash.js": "^1.0.3",
"minimalistic-assert": "^1.0.0",
"minimalistic-crypto-utils": "^1.0.1"
}
},
"inherits": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
},
"js-sha256": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"minimalistic-assert": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
"integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A=="
},
"minimalistic-crypto-utils": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz",
"integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo="
},
"randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
"integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==",
"requires": {
"safe-buffer": "^5.1.0"
}
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"uni-read-pages": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/uni-read-pages/-/uni-read-pages-1.0.5.tgz",
@@ -12,6 +188,11 @@
"resolved": "https://registry.npmjs.org/uni-simple-router/-/uni-simple-router-2.0.7.tgz",
"integrity": "sha512-8FKv5dw7Eoonm0gkO8udprrxzin0fNUI0+AvIphFkFRH5ZmP5ZWJ2pvnWzb2NiiqQSECTSU5VSB7HhvOSwD5eA=="
},
"unorm": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz",
"integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA=="
},
"uview-ui": {
"version": "2.0.19",
"resolved": "https://registry.npmjs.org/uview-ui/-/uview-ui-2.0.19.tgz",

View File

@@ -95,7 +95,7 @@
"path": "pages/address/index",
"name": "Address",
"style": {
"navigationBarTitleText": "地址"
"navigationBarTitleText": "收货地址"
}
}, {
"path": "pages/address/edit",
@@ -105,17 +105,25 @@
"enablePullDownRefresh": false
}
}, {
"path": "pages/pay/pay",
"path": "pages/pay/pay",
"name": "Pay",
"style": {
"navigationBarTitleText": "收银台",
"navigationBarBackgroundColor": "#FFFFFF"
}
}, {
"path": "pages/store/list",
"path": "pages/store/list",
"name": "StoreList",
"style": {
"navigationBarTitleText": "列表",
"navigationBarTitleText": "商品",
"navigationBarBackgroundColor": "#FFFFFF",
"enablePullDownRefresh": true
}
}, {
"path": "pages/store/meals",
"name": "StoreMeals",
"style": {
"navigationBarTitleText": "套餐",
"navigationBarBackgroundColor": "#FFFFFF",
"enablePullDownRefresh": true
}

View File

@@ -1,15 +1,15 @@
<template>
<view class="content">
<oct-address
:isTag="false"
:lists="addressList"
:isEdit="false"
:pattern="true"
editColor="#34CE98"
:btnStyle="{'backgroundColor': '#34CE98'}"
@onAddress="onInfo"
@onAdd="add"
>
</oct-address>
@onAdd="$Router.push({name: 'AddressEdit'})"
/>
</view>
</template>
@@ -73,7 +73,8 @@ export default {
},
methods: {
onInfo(val){
console.log(val)
this.$store.commit('setAddress', val)
this.$Router.back()
},
add(){
console.log("新增地址")

View File

@@ -1,52 +1,97 @@
<template>
<view class="content">
<!-- address -->
<view class="block address">
<uni-icons class="address-icon location" type="location-filled" size="24" color="#34CE98"></uni-icons>
<uni-icons class="address-icon arrows" type="right" size="20" color="#999"></uni-icons>
<view class="user"><text>唐明阳</text>18245180131</view>
<view class="city">黑龙江省哈尔滨市南岗区汉水路265号</view>
</view>
<block v-if="address != ''">
<view class="block address" @click="$Router.push({name: 'Address'})">
<uni-icons class="address-icon location" type="location-filled" size="24" color="#34CE98"></uni-icons>
<uni-icons class="address-icon arrows" type="right" size="20" color="#999"></uni-icons>
<view class="user"><text>{{address.name}}</text>{{address.phone}}</view>
<view class="city">{{address.address}}{{address.city}}</view>
</view>
</block>
<block v-else>
<view class="block address-new" @click="$Router.push({name: 'Address'})">
<uni-icons class="icon" type="plus" size="26" color="#34CE98"></uni-icons>添加收货地址
</view>
</block>
<!-- 订单产品 -->
<view class="block goods-box">
<view class="goods-item">
<image class="order-cover" src="https://yanxuan-item.nosdn.127.net/6d48e6ea51a06b1356ccda21497fdb14.png" mode="aspectFill"></image>
<view class="order-title">茅台王子酒 金王子 53 500毫升</view>
<view class="order-count">
<view class="order-price"><text></text>275.00</view>
<view class="order-sum">共1件</view>
<block v-for="(item, index) in goodsInfo" :key="index">
<view class="goods-item">
<image class="order-cover" :src="item.items[0].cover" mode="aspectFill"></image>
<view class="order-title">{{item.items[0].title}}</view>
<view class="order-count">
<view class="order-price"><text></text>{{item.items[0].price}}</view>
</view>
</view>
</view>
</block>
</view>
<!-- 订单信息 -->
<view class="block info-box">
<view class="info-item">
<view class="label">购买数量</view>
<uni-number-box class="info-number" :value="qty" :min="1" :max="999" @change="numberChange" />
</view>
<view class="info-item">
<view class="label">配送方式</view>
<view class="nowrap">快递</view>
</view>
<view class="info-item">
<view class="label">优惠金额</view>
<view class="nowrap">无优惠</view>
<view class="label">配送费用</view>
<view class="nowrap">{{freight <= 0 ? '免费': freight}}</view>
</view>
</view>
<!-- footer -->
<view class="order-footer">
<view class="total">总计<text>1399.00</text></view>
<view class="total">总计<text>{{total}}</text></view>
<button class="btn">确认订单</button>
</view>
</view>
</template>
<script>
import { buy, verify } from '@/apis/interfaces/store'
export default {
data() {
return {
goodsInfo : {},
expressPickerValue : 0,
addressId : '',
paramsId : '',
goodsNumber : ''
qty : 1,
goodsInfo : [],
total : 0,
freight : 0,
address : ""
};
},
computed:{
},
onShow(){
if(JSON.stringify(this.$store.getters.getAddress) !== '{}') this.address = this.$store.getters.getAddress
},
mounted() {
console.log(this.$Route.query)
this.getBuy()
},
methods:{
getBuy(){
buy({
goods_sku_id: this.$Route.query.skuId,
qty: this.qty
}).then(res => {
this.address = res.address
this.freight = res.freight
this.total = res.total
this.goodsInfo = res.detail
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
numberChange(e){
this.qty = e
this.getBuy()
}
}
}
</script>
@@ -99,6 +144,18 @@
}
}
}
.address-new{
padding: $padding;
text-align: center;
height: 90rpx;
line-height: 90rpx;
color: $main-color;
.icon{
vertical-align: middle;
margin-bottom: 8rpx;
margin-right: 10rpx;
}
}
// 订单列表
.goods-item{
display: flex;
@@ -130,8 +187,8 @@
}
}
.order-sum{
font-size: 26rpx;
color: #777;
font-size: $title-size-sm;
color: $text-gray;
}
}
}

View File

@@ -23,11 +23,13 @@
</view>
<view class="sales">销量{{goods.sales}}</view>
</view>
<view class="hr">
<!-- <view class="hr">
<text>详情</text>
</view>
</view> -->
<view class="imgs">
<rich-text :nodes="goods.content"></rich-text>
<block v-for="(item, index) in goods.content" :key="index">
<image :src="item" mode="widthFix"></image>
</block>
</view>
</view>
<!-- 立即购买 -->
@@ -65,7 +67,12 @@
})
},
buy(){
console.log(buy)
this.$Router.push({
name: 'StoreBuy',
params: {
skuId: this.goods.skus[0].sku_id
}
})
}
}
}

View File

@@ -17,7 +17,7 @@
</view>
<!-- 健康产品分类 -->
<u-scroll-list class="classify-box" indicatorColor="#ddd" indicatorActiveColor="#34CE98">
<view v-for="(item, index) in goodTabs" :key="index" class="classify-item">
<view v-for="(item, index) in goodTabs" :key="index" class="classify-item" @click="$Router.push({name: 'StoreList', params: {id: item.category_id, title: item.name}})">
<view class="classify-item-nav">
<image class="classify-item-cover" :src="item.cover"></image>
<view class="classify-item-title">{{item.name}}</view>
@@ -40,7 +40,7 @@
<!-- 推荐品类 -->
<view class="card-box">
<block v-for="(item, index) in meals" :key="index">
<view class="card-box-item" :style="{'backgrond': item.color}" @click="$Router.push({name: 'StoreList', params: {id: item.meal_id}})">
<view class="card-box-item" :style="{'backgrond': item.color}" @click="$Router.push({name: 'StoreMeals', params: {id: item.meal_id}})">
<view class="card-title">{{item.title}}</view>
<view class="card-subtitle">{{item.subtitle}}</view>
<image class="card-cover" :src="item.cover" mode="aspectFill"></image>
@@ -78,15 +78,12 @@
methods:{
getMall(){
mall().then(res => {
console.log(res)
this.banners = res.banners
this.goodsArr = res.goods
this.newGood = res.news
this.goodTabs = res.categories
this.meals = res.meals
uni.stopPullDownRefresh()
}).catch(err => {
console.log(err)
})
}
},

View File

@@ -1,5 +1,10 @@
<template>
<view>
<view class="content">
<!-- 分类 -->
<u-sticky bgColor="#fff" zIndex="99">
<u-tabs :list="classify" lineColor="#34CE98" @click="onTabs()"></u-tabs>
</u-sticky>
<!-- 分类商品 -->
<oct-goods
:lists="goodsArr"
color="#e6576b"
@@ -9,24 +14,52 @@
</template>
<script>
import { meals } from "@/apis/interfaces/store"
import { lists } from "@/apis/interfaces/store"
export default {
data() {
return {
goodsArr: []
goodsArr: [],
classify: [
{ name: "全部" },
{ name: "21天盒子" },
{ name: "7天盒子" },
{ name: "3天盒子" },
{ name: "复食餐" },
]
};
},
mounted(){
meals(this.$Route.query.id).then(res => {
uni.setNavigationBarTitle({
title: res.title
})
this.goodsArr = res.items
uni.setNavigationBarTitle({
title: this.$Route.query.title
})
this.getLists()
},
methods:{
// 商品列表
getLists() {
// {
// this.$Route.query.id
// }
lists({}).then(res => {
this.goodsArr = res.data
uni.stopPullDownRefresh()
})
},
// 二级分类筛选
onTabs(){
this.goodsArr = []
this.getLists()
}
},
onPullDownRefresh() {
this.getLists()
}
}
</script>
<style lang="scss">
<style lang="scss" scoped>
.content{
background: $window-color;
min-height: 100vh;
}
</style>

74
pages/store/meals.vue Normal file
View File

@@ -0,0 +1,74 @@
<template>
<view class="content">
<!-- banner -->
<view class="banner">
<image v-if="banner.length > 0" class="banner-cover" :src="banner[0].cover || ''" mode="aspectFill"></image>
</view>
<!-- 套餐列表 -->
<oct-goods
:lists="goodsArr"
color="#e6576b"
@onGoods="$Router.push({ name: 'StoreGoods', params: {id: $event.goods_id}})"
/>
</view>
</template>
<script>
import { meals } from "@/apis/interfaces/store"
export default {
data() {
return {
banner : [],
goodsArr: []
};
},
mounted(){
this.getMeals()
},
methods:{
getMeals(){
meals(this.$Route.query.id).then(res => {
console.log(res)
uni.setNavigationBarTitle({
title: res.meal.subtitle
})
this.banner = res.banner
this.goodsArr = res.meal.goods
uni.stopPullDownRefresh()
})
},
click(){
console.log('筛选')
}
},
onPullDownRefresh() {
this.getMeals()
}
}
</script>
<style lang="scss" scoped>
.content{
background: $window-color;
min-height: 100vh;
}
// banner
.banner{
position: relative;
width: 100%;
background-color: white;
padding-top: 40%;
&-text,
&-cover{
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
}
// 筛选
.classify-tabs{
background: white;
}
</style>

View File

@@ -13,7 +13,7 @@ router.beforeEach((to, from, next) => {
// 全局路由后置守卫
router.afterEach((to, from) => {
console.log('跳转结束')
// console.log('跳转结束')
})
export {

View File

@@ -13,18 +13,14 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
token : uni.getStorageSync('token') || '',
code : uni.getStorageSync('wxCode') || '',
coupongoods : []
address : {}
},
getters: {
getToken: state => {
return state.token
},
getCoupongoods: state => {
return state.coupongoods
},
getCode: state => {
return state.code
getAddress: state => {
return state.address
}
},
mutations: {
@@ -32,12 +28,8 @@ export default new Vuex.Store({
state.token = tokenString
uni.setStorageSync('token', tokenString)
},
setCoupongoods(state, value) {
state.coupongoods = value
},
setCode(state, value) {
state.code = value
uni.setStorageSync('wxCode', value)
setAddress(state, value) {
state.address = value
}
}
})

View File

@@ -9,8 +9,10 @@
<view class="address--lists">
<view class="address--item" :class="[pattern ? 'chunk': 'broad', {'edit': isEdit}]" v-for="(item, index) in lists" :key="index">
<view class="city">
<text v-if="item.default" class="city--tag city--default">默认</text>
<text v-if="item.tag && item.tag != ''" class="city--tag city--type">{{item.tag}}</text>
<block v-if="isTag">
<text v-if="item.default" class="city--tag city--default">默认</text>
<text v-if="item.tag && item.tag != ''" class="city--tag city--type">{{item.tag}}</text>
</block>
{{item.city}}
</view>
<view class="address">{{item.address}}</view>
@@ -79,6 +81,11 @@
default : () => {
return require('../../static/null-icon.png')
}
},
// 是否显示地址标签
isTag: {
type : Boolean,
default : true
}
}
}

View File

@@ -0,0 +1,25 @@
## 1.2.12021-11-22
- 修复 vue3中某些scss变量无法找到的问题
## 1.2.02021-11-19
- 优化 组件UI并提供设计资源详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-number-box](https://uniapp.dcloud.io/component/uniui/uni-number-box)
## 1.1.22021-11-09
- 新增 提供组件设计资源,组件样式调整
## 1.1.12021-07-30
- 优化 vue3下事件警告的问题
## 1.1.02021-07-13
- 组件兼容 vue3如何创建vue3项目详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
## 1.0.72021-05-12
- 新增 组件示例地址
## 1.0.62021-04-20
- 修复 uni-number-box 浮点数运算不精确的 bug
- 修复 uni-number-box change 事件触发不正确的 bug
- 新增 uni-number-box v-model 双向绑定
## 1.0.52021-02-05
- 调整为uni_modules目录规范
## 1.0.72021-02-05
- 调整为uni_modules目录规范
- 新增 支持 v-model
- 新增 支持 focus、blur 事件
- 新增 支持 PC 端

View File

@@ -0,0 +1,211 @@
<template>
<view class="uni-numbox">
<view @click="_calcValue('minus')" class="uni-numbox__minus uni-numbox-btns" :style="{background}">
<text class="uni-numbox--text" :class="{ 'uni-numbox--disabled': inputValue <= min || disabled }" :style="{color}">-</text>
</view>
<input :disabled="disabled" @focus="_onFocus" @blur="_onBlur" class="uni-numbox__value" type="number"
v-model="inputValue" :style="{color}" />
<view @click="_calcValue('plus')" class="uni-numbox__plus uni-numbox-btns" :style="{background}">
<text class="uni-numbox--text" :class="{ 'uni-numbox--disabled': inputValue >= max || disabled }" :style="{color}">+</text>
</view>
</view>
</template>
<script>
/**
* NumberBox 数字输入框
* @description 带加减按钮的数字输入框
* @tutorial https://ext.dcloud.net.cn/plugin?id=31
* @property {Number} value 输入框当前值
* @property {Number} min 最小值
* @property {Number} max 最大值
* @property {Number} step 每次点击改变的间隔大小
* @property {String} background 背景色
* @property {String} color 字体颜色(前景色)
* @property {Boolean} disabled = [true|false] 是否为禁用状态
* @event {Function} change 输入框值改变时触发的事件,参数为输入框当前的 value
* @event {Function} focus 输入框聚焦时触发的事件,参数为 event 对象
* @event {Function} blur 输入框失焦时触发的事件,参数为 event 对象
*/
export default {
name: "UniNumberBox",
emits: ['change', 'input', 'update:modelValue', 'blur', 'focus'],
props: {
value: {
type: [Number, String],
default: 1
},
modelValue: {
type: [Number, String],
default: 1
},
min: {
type: Number,
default: 0
},
max: {
type: Number,
default: 100
},
step: {
type: Number,
default: 1
},
background: {
type: String,
default: '#f5f5f5'
},
color: {
type: String,
default: '#333'
},
disabled: {
type: Boolean,
default: false
}
},
data() {
return {
inputValue: 0
};
},
watch: {
value(val) {
this.inputValue = +val;
},
modelValue(val) {
this.inputValue = +val;
}
},
created() {
if (this.value === 1) {
this.inputValue = +this.modelValue;
}
if (this.modelValue === 1) {
this.inputValue = +this.value;
}
},
methods: {
_calcValue(type) {
if (this.disabled) {
return;
}
const scale = this._getDecimalScale();
let value = this.inputValue * scale;
let step = this.step * scale;
if (type === "minus") {
value -= step;
if (value < (this.min * scale)) {
return;
}
if (value > (this.max * scale)) {
value = this.max * scale
}
}
if (type === "plus") {
value += step;
if (value > (this.max * scale)) {
return;
}
if (value < (this.min * scale)) {
value = this.min * scale
}
}
this.inputValue = (value / scale).toFixed(String(scale).length - 1);
this.$emit("change", +this.inputValue);
// TODO vue2 兼容
this.$emit("input", +this.inputValue);
// TODO vue3 兼容
this.$emit("update:modelValue", +this.inputValue);
},
_getDecimalScale() {
let scale = 1;
// 浮点型
if (~~this.step !== this.step) {
scale = Math.pow(10, String(this.step).split(".")[1].length);
}
return scale;
},
_onBlur(event) {
this.$emit('blur', event)
let value = event.detail.value;
if (!value) {
// this.inputValue = 0;
return;
}
value = +value;
if (value > this.max) {
value = this.max;
} else if (value < this.min) {
value = this.min;
}
const scale = this._getDecimalScale();
this.inputValue = value.toFixed(String(scale).length - 1);
this.$emit("change", +this.inputValue);
this.$emit("input", +this.inputValue);
},
_onFocus(event) {
this.$emit('focus', event)
}
}
};
</script>
<style lang="scss" scoped>
$box-height: 40rpx;
$bg: #f5f5f5;
$br: 2px;
$color: #333;
.uni-numbox {
/* #ifndef APP-NVUE */
display: inline-flex;
/* #endif */
flex-direction: row;
}
.uni-numbox-btns {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
width: $box-height;
height: $box-height;
border-radius: 50%;
flex-direction: row;
align-items: center;
justify-content: center;
background-color: $bg;
/* #ifdef H5 */
cursor: pointer;
/* #endif */
}
.uni-numbox__value {
margin: 0 2px;
width: 40px;
height: $box-height;
text-align: center;
font-size: 14px;
border-left-width: 0;
border-right-width: 0;
color: $color;
}
.uni-numbox--text {
// fix nvue
line-height: 20px;
font-size: 18px;
font-weight: 300;
margin-bottom: 6rpx;
color: $color;
}
.uni-numbox .uni-numbox--disabled {
color: #c0c0c0 !important;
/* #ifdef H5 */
cursor: not-allowed;
/* #endif */
}
</style>

View File

@@ -0,0 +1,85 @@
{
"id": "uni-number-box",
"displayName": "uni-number-box 数字输入框",
"version": "1.2.1",
"description": "NumberBox 带加减按钮的数字输入框组件,用户可以控制每次点击增加的数值,支持小数。",
"keywords": [
"uni-ui",
"uniui",
"数字输入框"
],
"repository": "https://github.com/dcloudio/uni-ui",
"engines": {
"HBuilderX": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"category": [
"前端组件",
"通用组件"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
},
"uni_modules": {
"dependencies": ["uni-scss"],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "y"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "y",
"QQ": "y"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
## NumberBox 数字输入框
> **组件名uni-number-box**
> 代码块: `uNumberBox`
带加减按钮的数字输入框。
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-number-box)
#### 如使用过程中有任何问题或者您对uni-ui有一些好的建议欢迎加入 uni-ui 交流群871950839

126
wallet/Wallet.js Normal file
View File

@@ -0,0 +1,126 @@
import Bitcore from "bitcore-lib"
import Mnemonic from "bitcore-mnemonic"
import secp256k1 from 'secp256k1'
import {
Address,
pubToAddress,
toBuffer,
toChecksumAddress,
intToBuffer
} from 'ethereumjs-util'
import coinType from './networks.js'
import basex from 'base-x'
export default class Wallet {
static coinType = coinType
/**
* 生成助记词
* @param {Object} lang
*/
static generateMnemonic(lang) {
if (lang) {
return (new Mnemonic(this.getLanguage(lang))).toString();
} else {
return (new Mnemonic()).toString();
}
}
/**
* 验证助记词
* @param {Object} code
* @param {Object} lang
*/
static validMnemonic(code, lang) {
if (lang) {
return Mnemonic.isValid(code, this.getLanguage(lang));
} else {
return Mnemonic.isValid(code);
}
}
/**
* 获取助记词字典
* @param {Object} lang
*/
static getLanguage(lang) {
return Mnemonic.Words[lang]
}
/**
* 转成硬钱包私钥
* @param {Object} code
*/
static toHDPrivateKey(code) {
return (new Mnemonic(code)).toHDPrivateKey()
}
/**
* 验证地址是否合法
* @param {Object} addr
*/
static isValidAddress(addr) {
return Bitcore.Address.isValid(addr)
}
/**
* 硬钱包私钥转成对应网络的 地址 和 私钥
* @param {Object} hdPrivateKey
* @param {Object} type
*/
static HDPrivateKeyToAddress(hdPrivateKey, type) {
const derived = hdPrivateKey.derive("m/44'/" + type.type + "'/0'/0/0");
if (type.type === 195) {
const ethAddr = this.getEthereumAddress(derived)
const addressBuffer = Buffer.concat([intToBuffer(0x41), ethAddr.buf], 21)
return {
address: Bitcore.encoding.Base58Check.encode(addressBuffer),
public_key: derived.privateKey.publicKey.toString(),
private_key: derived.privateKey.toString()
}
}
if (type.type === 144) {
let addr = derived.privateKey.toAddress(type.network).toString()
let deco = Bitcore.encoding.Base58.decode(addr)
return {
address: basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode(deco),
public_key: derived.privateKey.publicKey.toString(),
private_key: derived.privateKey.toString()
}
}
if (this.networkIsEthereum(type)) {
return {
address: toChecksumAddress(this.getEthereumAddress(derived).toString()),
public_key: derived.privateKey.publicKey.toString(),
private_key: derived.privateKey.toString()
}
}
return {
address: derived.privateKey.toAddress(type.network).toString(),
public_key: derived.privateKey.publicKey.toString(),
private_key: derived.privateKey.toString()
}
}
/**
* 以太坊地址格式转换
* @param {Object} derived
*/
static getEthereumAddress(derived) {
const publicKey = derived.hdPublicKey.publicKey.toBuffer()
const ethPublicKey = secp256k1.publicKeyConvert(publicKey, false)
.slice(1)
return Address.fromPublicKey(toBuffer(ethPublicKey))
}
/**
* 是否是以太坊网络
* @param {Object} type
*/
static networkIsEthereum(type) {
return type.isEthereum
}
}

29
wallet/_test.js Normal file
View File

@@ -0,0 +1,29 @@
import {
Wallet
} from "./Wallet.js"
const code = Wallet.generateMnemonic(this.defaultLanguage)
this.mnemonicCode = code
const hdPrivateKey = Wallet.toHDPrivateKey(this.mnemonicCode)
// const derived = hdPrivateKey.derive("m/44'/61'/0'/0/0");
// const publicKey = derived.hdPublicKey.publicKey.toBuffer()
// const ethPublicKey = secp256k1.publicKeyConvert(publicKey, false)
// .slice(1)
// const ethAddr = Address.fromPublicKey(toBuffer(ethPublicKey)).toString();
// console.log(toChecksumAddress(ethAddr));
// console.log(Address.fromPrivateKey(hdPrivateKey.hdPublicKey.publicKey.toBuffer()));
var addr = []
for (var i in this.coinType) {
let whk = Wallet.HDPrivateKeyToAddress(hdPrivateKey, i)
let parmas = {
name: this.coinType[i],
address: whk.address,
private_key: whk.private_key,
}
addr.push(parmas)
}
this.address = addr

24
wallet/index.js Normal file
View File

@@ -0,0 +1,24 @@
import store from "@/store/index.js"
const USE_SOTER_AUTH_KEY = 'USE_SOTER_AUTH_KEY'
/**
* 初始化配置
*/
const initWalletConfigs = () => {
// 生物识别
const USE_SOTER = Boolean(uni.getStorageSync(USE_SOTER_AUTH_KEY))
store.dispatch('wallet/setSoterAuth', USE_SOTER)
// 获取默认钱包
}
const setSoterAuthStatus = (opt) => {
uni.setStorageSync(USE_SOTER_AUTH_KEY, opt)
store.dispatch('wallet/setSoterAuth', opt)
}
export default {
USE_SOTER_AUTH_KEY,
setSoterAuthStatus,
initWalletConfigs
}

209
wallet/networks.js Normal file
View File

@@ -0,0 +1,209 @@
import Bitcore from "bitcore-lib"
export default [{
type: 0,
name: '比特币',
symbol: 'BTC',
code: 'btc',
isEthereum: false,
network: Bitcore.Networks.mainnet
},
{
type: 60,
name: '以太坊',
symbol: 'ETH',
code: 'eth',
isEthereum: true
},
{
type: 61,
name: '以太经典',
symbol: 'ETC',
code: 'etc',
isEthereum: true
},
{
type: 60,
name: '赤子心',
symbol: 'CZX',
code: 'eth_0x3a2a239b1bdaae768ffa06314d523e88e98d4d1f',
isEthereum: true
},
// {
// type: 2,
// name: '莱特币',
// symbol: 'LTC',
// isEthereum: false,
// network: Bitcore.Networks.add({
// name: 'LTC',
// alias: 'LTC',
// pubkeyhash: 0x30,
// privatekey: 0x32,
// scripthash: 0xb0,
// bech32prefix: 'ltc',
// xpubkey: 0x019da462,
// xprivkey: 0x019d9cfe,
// networkMagic: 0xdbb6c0fb
// })
// },
{
type: 3,
name: '狗狗币',
symbol: 'DOGE',
code: 'doge',
isEthereum: false,
network: Bitcore.Networks.add({
name: 'DOGE',
alias: 'DOGE',
pubkeyhash: 0x1e,
privatekey: 0x16,
scripthash: 0x9e,
bech32prefix: 'doge',
xpubkey: 0x02facafd,
xprivkey: 0x02fac398,
networkMagic: 0xc0c0c0c0
})
},
// {
// type: 133,
// name: '零币',
// symbol: 'ZEC',
// isEthereum: false,
// network: Bitcore.Networks.add({
// name: 'ZEC',
// alias: 'ZEC',
// pubkeyhash: 0x1e,
// privatekey: 0x16,
// scripthash: 0x9e,
// bech32prefix: 'doge',
// xpubkey: 0x02facafd,
// xprivkey: 0x02fac398,
// networkMagic: 0xc0c0c0c0
// })
// },
// {
// type: 144,
// name: 'XPR - 瑞波币',
// symbol: 'XPR',
// isEthereum: false,
// network: Bitcore.Networks.add({
// name: 'XPR',
// alias: 'XPR',
// pubkeyhash: 0x1e,
// privatekey: 0x16,
// scripthash: 0x9e,
// bech32prefix: 'doge',
// xpubkey: 0x02facafd,
// xprivkey: 0x02fac398,
// networkMagic: 0xc0c0c0c0
// })
// },
// {
// type: 145,
// name: '比特现金',
// symbol: 'BCH',
// isEthereum: false,
// network: Bitcore.Networks.add({
// name: 'BCH',
// alias: 'BCH',
// pubkeyhash: 0x00,
// privatekey: 0x05,
// scripthash: 0x80,
// bech32prefix: 'bitcoincash',
// xpubkey: 0x0488b21e,
// xprivkey: 0x0488ade4,
// networkMagic: 0xd9b4bef9
// })
// },
// {
// type: 195,
// name: '波场',
// symbol: 'TRX',
// isEthereum: false,
// network: Bitcore.Networks.add({
// name: 'TRX',
// alias: 'TRX',
// pubkeyhash: 0x41,
// privatekey: 0x05,
// scripthash: 0x80,
// bech32prefix: '',
// xpubkey: 0x0488b21e,
// xprivkey: 0x0488ade4
// })
// },
{
type: 195,
name: 'USDT(TRC20)',
symbol: 'USDT',
code: 'trx_TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
isEthereum: false,
network: Bitcore.Networks.add({
name: 'USDT',
alias: 'USDT',
pubkeyhash: 0x41,
privatekey: 0x05,
scripthash: 0x80,
bech32prefix: '',
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4
})
},
{
type: 195,
name: 'USDT(ERC20)',
symbol: 'USDT',
code: 'eth_0xdac17f958d2ee523a2206206994597c13d831ec7',
isEthereum: true
},
{
type: 0,
name: 'USDT(OMNI)',
symbol: 'USDT',
code: 'usdt',
isEthereum: false,
network: Bitcore.Networks.mainnet
},
{
type: 13107,
name: '比特元',
symbol: 'BTY',
code: 'bty',
isEthereum: false,
network: Bitcore.Networks.add({
name: 'BTY',
alias: 'BTY',
pubkeyhash: 0x00,
privatekey: 0x05,
scripthash: 0x80,
bech32prefix: 'bityuan',
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4,
networkMagic: 0xd9b4bef9
})
},
// {
// type: 60,
// name: '元链',
// symbol: 'YCC',
// isEthereum: true
// },
{
type: 13107,
name: 'JZC',
symbol: 'JZC',
code: 'bty',
isEthereum: false,
network: Bitcore.Networks.add({
name: 'JZC',
alias: 'JZC',
pubkeyhash: 0x00,
privatekey: 0x05,
scripthash: 0x80,
bech32prefix: 'bityuan',
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4,
networkMagic: 0xd9b4bef9
})
}
]