当前位置:   article > 正文

uniapp初级入门-05模拟商城完结篇_uniapp应用商店界面代码

uniapp应用商店界面代码

这个代码就是基本完结了。我把全部代码都贴出来,供大家参考学习。

项目情况截图

代码

api

home index.js

  1. import request from '@/api/request.js'
  2. export const getBannerAds = () => {
  3. return request({
  4. url:'/lejuClient/home/bannerAds',
  5. method: 'GET'
  6. })
  7. }
  8. export const doLogin = (data) => {
  9. return request({
  10. url:'/lejuClient/login/doLogin',
  11. method: 'POST',
  12. data: data
  13. })
  14. }
  15. export const findCategory = (id) => {
  16. return request({
  17. url:'/lejuClient/productCategory/findCategory/' + id,
  18. method: 'GET'
  19. })
  20. }
  21. export const getHotList = ()=> {
  22. return request({
  23. url:'/lejuClient/home/hotList',
  24. method: 'GET'
  25. })
  26. }

info index.js

  1. import request from '@/api/request.js'
  2. export const getDetail = (productId)=> {
  3. return request({
  4. url: '/lejuClient/product/productDetail/' + productId,
  5. method: 'GET'
  6. })
  7. }
  8. export const addCart = (data)=> {
  9. return request({
  10. url:'/lejuClient/cart/addCart',
  11. method: 'POST',
  12. data: data
  13. })
  14. }
  15. export const addPreOrder = (data)=> {
  16. return request({
  17. url: '/lejuClient/order/addPreOrder',
  18. method: 'POST',
  19. data: data
  20. })
  21. }

kind goods goods.js

  1. import request from '@/api/request.js'
  2. export const getProductList = (start,limit,data)=> {
  3. return request({
  4. url:`/lejuClient/product/findProductList/${start}/${limit}`,
  5. method:'POST',
  6. data:data
  7. })
  8. }

kind list list.js

  1. import request from '@/api/request.js'
  2. export const getCategory = (categoryId)=>{
  3. return request({
  4. url:'/lejuClient/productCategory/findCategory/' + categoryId,
  5. method: 'GET'
  6. })
  7. }
  8. export const getProductList = (start,limit,data)=> {
  9. return request({
  10. url:`/lejuClient/product/findProductList/${start}/${limit}`,
  11. method:'POST',
  12. data:data
  13. })
  14. }

kind index.js

  1. import request from '../request.js'
  2. export const getAllCategory = ()=> {
  3. return request({
  4. url:'/lejuClient/productCategory/findAllCategory'
  5. })
  6. }

mine login login.js

  1. import request from '@/api/request.js'
  2. export const doLogin = (data)=> {
  3. return request({
  4. url:'/lejuClient/login/doLogin',
  5. method: 'POST',
  6. data: data
  7. })
  8. }

mine register index.js

  1. import request from '@/api/request.js'
  2. export const doRegister = (data)=> {
  3. return request({
  4. url:'/lejuClient/member/register',
  5. method:'POST',
  6. data: data
  7. })
  8. }

mine index.js

  1. import request from '@/api/request.js'
  2. export const getMemberInfo = ()=>{
  3. return request({
  4. url:'/lejuClient/login/getMemberInfo',
  5. method: 'GET'
  6. })
  7. }

order addres index.js

  1. import request from '@/api/request.js'
  2. export const getAllAddress = ()=> {
  3. return request({
  4. url:'/lejuClient/address/findAllAddress',
  5. method: 'GET'
  6. })
  7. }

order index.js

  1. import request from '@/api/request.js'
  2. export const getPreOrderById = (orderId)=> {
  3. return request({
  4. url:'/lejuClient/order/getPreOrderById/' + orderId,
  5. method: 'GET'
  6. })
  7. }
  8. export const addConfirmOrder = (data)=> {
  9. return request({
  10. url:'/lejuClient/order/addConfirmOrder',
  11. method: 'POST',
  12. data: data
  13. })
  14. }

baseurl.js

  1. let baseUrl = "";
  2. if(process.env.MODE_ENV == 'development'){
  3. console.log("开发环境");
  4. baseUrl = "http://leju.bufan.cloud";
  5. }else{
  6. console.log("生产环境");
  7. baseUrl = "http://leju.bufan.cloud";
  8. }
  9. export default baseUrl

request.js

  1. import baseUrl from '@/api/baseUrl.js'
  2. let instance = (config) => {
  3. return new Promise((resolve,rejected)=>{
  4. uni.request({
  5. url: baseUrl + config.url,
  6. timeout: 5000,
  7. data:config.data,
  8. method: config.method,
  9. header:{
  10. token: uni.getStorageSync("b-token")
  11. },
  12. success(res){
  13. if(res.data.success == false){
  14. uni.showToast({
  15. title:res.data.message,
  16. icon:'none',
  17. mask: true,
  18. duration: 3000
  19. })
  20. }else{
  21. resolve(res.data);
  22. }
  23. }
  24. })
  25. })
  26. }
  27. export default instance;

minxins

index.js

  1. let obj = {
  2. methods:{
  3. checkLogin(){
  4. let token = uni.getStorageSync("b-token");
  5. if(token){
  6. let userInfo = uni.getStorageSync("b-userInfo");
  7. this.userInfo = userInfo;
  8. return true;
  9. }else{
  10. uni.showModal({
  11. title:'登录提示',
  12. content:'暂未登录,是否重新登录',
  13. success(res) {
  14. //console.log(res)
  15. if(res.confirm){
  16. //清空本地数据
  17. uni.clearStorageSync();
  18. uni.navigateTo({
  19. url:'/pages/mine/login/login'
  20. });
  21. }else{
  22. uni.showToast({
  23. title:'已取消登录',
  24. icon:'error'
  25. });
  26. uni.clearStorageSync();
  27. }
  28. }
  29. })
  30. return false;
  31. }
  32. }
  33. }
  34. }
  35. export default obj

pages

find find.vue

  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script>
  6. import mix from '@/minxins/index.js'
  7. export default {
  8. data() {
  9. return {
  10. };
  11. },
  12. mixins:[mix],
  13. onShow() {
  14. this.checkLogin();
  15. }
  16. }
  17. </script>
  18. <style lang="scss" scoped>
  19. </style>

home home.vue

  1. <template>
  2. <view>
  3. <view class="nav-area">
  4. <!-- 这里状态栏 -->
  5. </view>
  6. <!-- 轮播图 -->
  7. <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
  8. <swiper-item v-for="item in barnerList" :key="item.id">
  9. <img :src="item.pic" alt="" style="width:100%;">
  10. </swiper-item>
  11. </swiper>
  12. <!-- <button type="default" @tap="login">登录</button> -->
  13. <!-- <button type="default" @tap="doFind">获取分类</button> -->
  14. <view class="box">
  15. </view>
  16. <view class="parent">
  17. <view v-for="item in 6" :key="item">
  18. {{ item}}
  19. </view>
  20. </view>
  21. <swiper
  22. :indicator-dots="true"
  23. :autoplay="true"
  24. :interval="3000"
  25. :duration="1500"
  26. circular
  27. :display-multiple-items="3" >
  28. <swiper-item v-for="item in hotList" :key="item.id">
  29. <image :src="item.pic" mode="" style="width:95%;"></image>
  30. </swiper-item>
  31. </swiper>
  32. </view>
  33. </template>
  34. <script>
  35. import { getBannerAds, doLogin, findCategory, getHotList} from '@/api/home/index.js'
  36. export default {
  37. data() {
  38. return {
  39. barnerList:[],
  40. hotList:[],
  41. };
  42. },
  43. methods: {
  44. // login(){
  45. // doLogin({
  46. // username:'17596496508',
  47. // password: '123456'
  48. // }).then(res=>{
  49. // //console.log(res)
  50. // });
  51. // },
  52. // doFind(){
  53. // findCategory(1).then(res=>{
  54. // //console.log(res)
  55. // })
  56. // }
  57. },
  58. onLoad(options) {
  59. getBannerAds().then(res=>{
  60. this.barnerList = res.data.items;
  61. })
  62. getHotList().then(res=>{
  63. console.log(res);
  64. this.hotList = res.data.items;
  65. })
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. .nav-area{
  71. height: var(--status-bar-height);
  72. width: 100%;
  73. }
  74. .box{
  75. width: 208rpx;
  76. height: 140rpx;
  77. background-color: $uni-bg-color-hover;
  78. }
  79. .parent {
  80. display: flex;
  81. align-items: center;
  82. overflow-x: auto;
  83. view{
  84. height: 200rpx;
  85. width: 300rpx;
  86. background-color: gray;
  87. flex-shrink: 0;
  88. }
  89. }
  90. </style>

index index.vue

  1. <template>
  2. <view class="content">
  3. <view>
  4. {{text}}
  5. </view>
  6. <view v-text="text">
  7. </view>
  8. <view v-for="item in list" :key="item.name" @tap="printName(item)">
  9. {{item.name}}
  10. </view>
  11. <view v-show="isShow">这是一行文字</view>
  12. <button type="default" @tap="toggleText">点击控制文字显示与隐藏</button>
  13. <view :class="{red:isActive}">文字颜色会变化</view>
  14. <button type="default" @tap="changeColor">点击变换颜色</button>
  15. <view :style="{color:isChange ? 'red':''}">内联样式变化文字颜色</view>
  16. <button type="default" @tap="changeStyle">点击变换style</button>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data(){
  22. return {
  23. isChange:false,
  24. isActive:false,
  25. isShow: true,
  26. text:'张三',
  27. list:[
  28. {name:'苹果'},
  29. {name:'香蕉'},
  30. {name:'橘子'},
  31. {name:'火龙果'},
  32. ]
  33. }
  34. },
  35. methods: {
  36. changeStyle(){
  37. this.isChange = !this.isChange
  38. },
  39. changeColor(){
  40. this.isActive = !this.isActive;
  41. },
  42. toggleText(){
  43. this.isShow = !this.isShow;
  44. },
  45. printName(obj){
  46. console.log(obj.name);
  47. }
  48. }
  49. }
  50. </script>
  51. <style>
  52. .red{
  53. color: red;
  54. }
  55. </style>

info info.vue

  1. <template>
  2. <view class="info">
  3. <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
  4. <swiper-item v-for="(item,index) in albumPics" :key="index">
  5. <view class="swiper-item">
  6. <img :src="item" alt="" style="width: 100%;">
  7. </view>
  8. </swiper-item>
  9. </swiper>
  10. <view class="row">商品名称:{{productData.name}}</view>
  11. <view class="row">商品价格:¥{{productData.price}}</view>
  12. <view class="row">商品描述:{{productData.description}}</view>
  13. <view class="row">明细标题:{{productData.detailTitle}}</view>
  14. <view class="row">明细描述:{{productData.detailDesc}}</view>
  15. <view class="row">品牌名称:{{productData.brandName}}</view>
  16. <view class="row">品牌目录:{{productData.productCategoryName}}</view>
  17. <mp-html :content="productData.detailMobileHtml"></mp-html>
  18. <view class="mask" @touchmove.stop.prevent v-if="isMaskShow">
  19. <view class="box">
  20. <image :src="picUrl" mode="" class="pic"></image>
  21. <uni-icons type="close" @tap="isMaskShow = false" style="position: absolute;right: 120rpx;top: 260rpx;"></uni-icons>
  22. <view>商品选择</view>
  23. <view class="sp-data">
  24. <view
  25. v-for="(item,idx) in productData.skuList"
  26. :key="item.id"
  27. class="sp-data-row"
  28. :class="spDataSelectedIndex == idx ? 'active': ''" @tap="spDataSelect(idx)">
  29. <text v-for="(ele,index) in item.spData" :key="index" class="sp-data-item">
  30. {{ele.key}}:{{ele.value}}
  31. </text>
  32. </view>
  33. </view>
  34. <view style="width: 60%;margin: 0 auto;">
  35. <button type="warn" size="default" @tap="confirm">购买</button>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="fixed-btn">
  40. <uni-icons type="headphones" class="btn-icon"></uni-icons>
  41. <button type="default" class="btn-cart" @tap="addCart(0)">添加至购物车</button>
  42. <button type="primary" class="btn-buy" @tap="goBuy(1)">立即购买</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { getDetail, addCart, addPreOrder } from '@/api/info/index.js'
  48. import mix from '@/minxins/index.js'
  49. import { registerRuntimeCompiler } from "vue";
  50. export default {
  51. mixins:[mix],
  52. data() {
  53. return {
  54. currentTap:0, //0购物车,1立即购买
  55. picUrl:'',
  56. spDataSelectedIndex: null,
  57. isMaskShow: false,
  58. productId:null,
  59. productData: {},
  60. albumPics:[],
  61. obj:{
  62. img:"width:90%;"
  63. }
  64. };
  65. },
  66. methods:{
  67. //确认购买
  68. confirm(){
  69. //先判断是否登录
  70. if(!this.checkLogin()){
  71. return;
  72. }
  73. //判断是否选择了规格
  74. if(this.spDataSelectedIndex == null) {
  75. uni.showToast({
  76. title:'请选择规格',
  77. icon:'error'
  78. });
  79. return;
  80. }
  81. //获取sku
  82. let sku = this.productData.skuList[this.spDataSelectedIndex];
  83. if(this.currentTap == 0){
  84. console.log('添加至购物车')
  85. addCart({
  86. productId: sku.productId,
  87. productSkuId: sku.id,
  88. quantity: 1 //默认了
  89. }).then(res=>{
  90. console.log(res)
  91. uni.showToast({
  92. title:res.message,
  93. icon:'success'
  94. });
  95. this.isMaskShow = false;
  96. })
  97. }else if(this.currentTap == 1){
  98. console.log('立即购买');
  99. addPreOrder({
  100. addressId: "",
  101. orderId: "",
  102. orderItemList: [
  103. {
  104. cartId: "",
  105. productId: sku.productId,
  106. productQuantity: 1,
  107. productSkuId: sku.id
  108. }
  109. ],
  110. payType: 0,
  111. sourceType: 1
  112. }).then(res=>{
  113. console.log(res);
  114. this.isMaskShow = false;
  115. uni.showToast({
  116. title:`下单${res.message},订单号是${res.data.orderId}`,
  117. icon:'none',
  118. mask:true,
  119. duration:2000
  120. });
  121. setTimeout(()=>{
  122. uni.navigateTo({
  123. url:'/pages/order/order?orderId=' + res.data.orderId
  124. });
  125. },2000);
  126. })
  127. }
  128. },
  129. //选中
  130. spDataSelect(index){
  131. this.spDataSelectedIndex = index;
  132. this.picUrl = this.productData.skuList[index].pic;
  133. },
  134. //添加至购物车
  135. addCart(val){
  136. this.goBuy(val);
  137. },
  138. //立即购买
  139. goBuy(val){
  140. this.currentTap = val;
  141. this.isMaskShow = !this.isMaskShow;
  142. }
  143. },
  144. onLoad(options) {
  145. this.productId = options.id
  146. getDetail(this.productId).then(res=>{
  147. console.log(res)
  148. res.data.product.skuList.forEach(ele=>{
  149. ele.spData = JSON.parse(ele.spData);
  150. });
  151. this.productData = res.data.product;
  152. this.albumPics = this.productData.albumPics.split(",");
  153. uni.setNavigationBarTitle({
  154. title: this.productData.name
  155. });
  156. })
  157. }
  158. }
  159. </script>
  160. <style lang="scss">
  161. .info{
  162. .row{
  163. min-height: 100rpx;
  164. width: 100%;
  165. font-size: 18px;
  166. padding: 10px 10px;
  167. margin-bottom: 20rpx;
  168. margin-top: 10rpx;
  169. }
  170. .mask{
  171. width: 100%;
  172. height: 100vh;
  173. position: fixed;
  174. top: 0;
  175. left: 0;
  176. z-index: 999;
  177. background-color: rgba(0,0,0,0.6);
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. .box{
  182. width: 80%;
  183. min-height: 1000rpx;
  184. margin: 0 auto;
  185. background-color: #fff;
  186. .pic{
  187. width: 240rpx;
  188. height: 240rpx;
  189. border: 2px solid #FFC6CC;
  190. border-radius: 100rpx;
  191. position: relative;
  192. top: -90rpx;
  193. left: 60rpx;
  194. background-color: #FFC6CC;
  195. }
  196. .sp-data{
  197. height: 500rpx;
  198. overflow-y: scroll;
  199. .sp-data-row{
  200. height: 60rpx;
  201. line-height: 60rpx;
  202. width: 100%;
  203. margin: 15rpx 0;
  204. padding-left: 40rpx;
  205. box-sizing: border-box;
  206. .sp-data-item{
  207. margin-left: 25rpx;
  208. border: 1px solid green;
  209. border-radius: 10rpx;
  210. padding: 10rpx;
  211. height: 40rpx;
  212. font-size: 14px;
  213. }
  214. }
  215. .active{
  216. background-color: #E2E2E2;
  217. }
  218. }
  219. }
  220. }
  221. .fixed-btn{
  222. display: flex;
  223. align-items: center;
  224. position: fixed;
  225. bottom: 0;
  226. left: 0;
  227. width: 100%;
  228. border: 1px solid #cccccc;
  229. padding: 10px;
  230. background-color: #fff;
  231. button{
  232. width: 40%;
  233. margin: 0;
  234. border-radius: 0;
  235. }
  236. .btn-icon{
  237. width: 15%;
  238. }
  239. .btn-cart{
  240. background-color: #E2E2E2;
  241. }
  242. .btn-buy{
  243. background-color: #344B44;
  244. }
  245. }
  246. }
  247. </style>

kind goods goods.vue

  1. <template>
  2. <view>
  3. <view class="tab">
  4. <view class="tab-item" v-for="(item,index) in tabList" :key="index">
  5. <view :class="{active: index == currentTabIndex }" @tap="tabClick(index)">
  6. {{item.name}}
  7. </view>
  8. <view v-if=" item.name == '销量' || item.name == '价格'" class="icon-box">
  9. <uni-icons type="up" size="16" :color="item.current == 'up'?'#dd524d': ''"></uni-icons>
  10. <uni-icons type="down" size="16" :color="item.current == 'down'?'#dd524d': ''"></uni-icons>
  11. </view>
  12. </view>
  13. </view>
  14. <ul class="product-area">
  15. <li v-for="item in productList" :key="item.id" @tap="goInfo(item)">
  16. <img :src="item.pic" alt="" />
  17. <view>{{item.name}}</view>
  18. <view>¥{{item.price}}</view>
  19. <view>{{item.brandName}}</view>
  20. </li>
  21. </ul>
  22. </view>
  23. </template>
  24. <script>
  25. import { getProductList } from '@/api/kind/goods/goods.js'
  26. export default {
  27. data() {
  28. return {
  29. total: 0,
  30. start: 1,
  31. limit: 4,
  32. sortBy:'',
  33. desc: 0,
  34. currentTabIndex: 0,
  35. categoryId: 0,
  36. productList:[],
  37. tabList:[
  38. {
  39. name:'新品',
  40. current:'default', //default up down
  41. },
  42. {
  43. name:'销量',
  44. current:'default', //default up down
  45. },
  46. {
  47. name:'价格',
  48. current:'default', //default up down
  49. },
  50. {
  51. name:'筛选',
  52. current:'default', //default up down
  53. },
  54. ]
  55. }
  56. },
  57. methods: {
  58. goInfo(item){
  59. console.log(item)
  60. uni.navigateTo({
  61. url:'/pages/info/info?id=' + item.id
  62. })
  63. },
  64. tabClick(index){
  65. //重置数据
  66. this.productList = [];
  67. //当前索引保存起来
  68. this.currentTabIndex = index;
  69. //除了当前点击项,其余项恢复默认标识
  70. this.tabList.forEach((ele,idx)=>{
  71. if(idx != index){
  72. ele.current = 'default';
  73. }
  74. });
  75. //获取当前项
  76. let item = this.tabList[index];
  77. //判断是升序,还是降序
  78. if(item.current == 'default'){
  79. this.tabList[index].current = 'up';
  80. this.desc = 0; //升序
  81. }else if(item.current == 'up'){
  82. this.tabList[index].current = 'down';
  83. this.desc = 1; //降序
  84. }else {
  85. this.tabList[index].current = 'up';
  86. this.desc = 0; //升序
  87. }
  88. //判断是销量排序,还是价格排序
  89. if(item.name =='销量'){
  90. this.sortBy = 'sale'
  91. }else if(item.name =='价格'){
  92. this.sortBy = 'price'
  93. }
  94. //请求接口获取数据
  95. this.getData();
  96. },
  97. getData(){
  98. let data = {
  99. "brandId": "",
  100. "categoryId": this.categoryId,
  101. "isDesc": this.desc,
  102. "keywords": "",
  103. "sortBy": this.sortBy
  104. }
  105. //调用接口函数
  106. getProductList(this.start,this.limit,data).then(res=>{
  107. //console.log(res)
  108. this.productList.push(...res.data.rows);
  109. this.total = res.data.total;
  110. uni.stopPullDownRefresh();
  111. })
  112. }
  113. },
  114. onLoad(options) {
  115. //从页面传参中获取id
  116. this.categoryId = options.id;
  117. //然后获取数据
  118. this.getData();
  119. },
  120. //上拉加载
  121. onReachBottom(){
  122. //判断目前数据小于总数据时,继续获取数据
  123. if(this.productList.length < this.total){
  124. this.start += 1;
  125. this.getData();
  126. }else
  127. {
  128. console.log("没有更多了")
  129. }
  130. },
  131. //下拉刷新
  132. onPullDownRefresh(){
  133. this.start = 1;
  134. this.productList = [];
  135. this.getData();
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. .tab{
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-around;
  144. padding: 10px 0;
  145. .tab-item{
  146. display: flex;
  147. align-items: center;
  148. .icon-box{
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. flex-direction: column;
  153. }
  154. .active{
  155. color: #dd524d;
  156. }
  157. }
  158. }
  159. .product-area{
  160. list-style: none;
  161. width: 100%;
  162. padding: 10rpx;
  163. li{
  164. width: 45%;
  165. height: 600rpx;
  166. float: left;
  167. border: 1px solid gray;
  168. text-align: center;
  169. margin: 10rpx;
  170. img{
  171. width: 100%;
  172. height: 400rpx;
  173. }
  174. text{
  175. color: gray;
  176. }
  177. }
  178. }
  179. </style>

king list list.vue

  1. <template>
  2. <view>
  3. 二级分类页
  4. <button type="default" @tap="goKind">api方式跳转回分类页</button>
  5. <button type="default" @tap="goBack">返回上级菜单</button>
  6. <navigator url="/pages/kind/kind" open-type="switchTab">组件方式跳转回分类页</navigator>
  7. <navigator :delta="1" open-type="navigateBack">组件方式回退上一级</navigator>
  8. <view class="nav-item" v-for="item in categoryList" :key="item.id" @tap="catetoryClick(item)">
  9. <!-- <image :src="item.icon" mode=""></image> -->
  10. <text>{{item.name}}</text>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import { getCategory} from '@/api/kind/list/list.js'
  16. export default {
  17. data() {
  18. return {
  19. categoryId:0,
  20. categoryList:[]
  21. };
  22. },
  23. methods:{
  24. catetoryClick(obj){
  25. console.log(obj)
  26. uni.navigateTo({
  27. url:'/pages/kind/goods/goods?id=' + obj.id
  28. })
  29. },
  30. goKind(){
  31. uni.switchTab({
  32. url:'/pages/kind/kind'
  33. })
  34. },
  35. goBack(){
  36. uni.navigateBack({
  37. delta:1
  38. })
  39. }
  40. },
  41. onLoad(options) {
  42. this.categoryId = options.id;
  43. getCategory(this.categoryId).then(res=>{
  44. //console.log(res)
  45. this.categoryList = res.data.category.children;
  46. })
  47. }
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. .nav-item{
  52. width: 100%;
  53. height: 110rpx;
  54. border: 1px solid gray;
  55. margin-bottom: 10px;
  56. box-sizing: border-box;
  57. text-align: center;
  58. font-size: 18px;
  59. font-weight: bold;
  60. line-height: 110rpx;
  61. background-color: $uni-bg-color-grey;
  62. }
  63. </style>

kind kind.vue

  1. <template>
  2. <view>
  3. <button type="default" @tap="goProduct">api方式跳转到商品页</button>
  4. <navigator url="/pages/kind/list/list">组件方式跳转至商品页</navigator>
  5. <view class="nav-item" v-for="item in categoryList" :key="item.pmsProductCategory.id" @tap="catetoryClick(item)">
  6. <!-- <image :src="item.pmsProductCategory.icon" mode=""></image> -->
  7. <text>{{item.pmsProductCategory.name}}</text>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import { getAllCategory } from '@/api/kind/index.js'
  13. export default {
  14. data() {
  15. return {
  16. categoryList:[]
  17. };
  18. },
  19. methods: {
  20. goProduct(){
  21. uni.navigateTo({
  22. url:'/pages/kind/list/list'
  23. })
  24. },
  25. catetoryClick(obj){
  26. uni.navigateTo({
  27. url:'/pages/kind/list/list?id=' + obj.pmsProductCategory.id
  28. })
  29. }
  30. },
  31. onLoad() {
  32. getAllCategory().then(res=>{
  33. console.log(res)
  34. this.categoryList = res.data.items;
  35. })
  36. }
  37. }
  38. </script>
  39. <style lang="scss">
  40. navigator{
  41. width: 100%;
  42. height: 150rpx;
  43. line-height: 150rpx;
  44. text-align: center;
  45. }
  46. .nav-item{
  47. width: 100%;
  48. height: 150rpx;
  49. border: 1px solid gray;
  50. margin-bottom: 10px;
  51. box-sizing: border-box;
  52. text-align: center;
  53. font-size: 18px;
  54. font-weight: bold;
  55. line-height: 150rpx;
  56. background-color: $uni-bg-color-grey;
  57. }
  58. </style>

mine login login.vue

  1. <template>
  2. <view class="login-area">
  3. <view class="row">
  4. <image src="/static/logo.png" style="width: 300rpx;height: 250rpx;margin: 0 auto;display: block;"></image>
  5. </view>
  6. <view class="row">
  7. <input type="text" class="input" placeholder="用户名" v-model="loginForm.username"/>
  8. </view>
  9. <view class="row">
  10. <input type="password" class="input" placeholder="密码" v-model="loginForm.password"/>
  11. </view>
  12. <view class="row">
  13. <button type="default" @tap="login" class="btn">登录</button>
  14. </view>
  15. <navigator url="/pages/mine/register/register" class="register">没有账号?注册一个</navigator>
  16. </view>
  17. </template>
  18. <script>
  19. import {doLogin} from '@/api/mine/login/login.js'
  20. import { getMemberInfo } from '@/api/mine/index.js'
  21. export default {
  22. data() {
  23. return {
  24. loginForm:{
  25. username:'17596496508',
  26. password:'123456'
  27. }
  28. };
  29. },
  30. methods:{
  31. login(){
  32. doLogin(this.loginForm).then(res=>{
  33. console.log(res)
  34. uni.showToast({
  35. title:'登录成功',
  36. icon:'success'
  37. });
  38. //登录成功,存token
  39. uni.setStorageSync("b-token",res.data.token);
  40. //同时获取用户信息,存用户
  41. getMemberInfo().then(res=>{
  42. uni.setStorageSync("b-userInfo",res.data.userInfo);
  43. });
  44. setTimeout(()=>{
  45. uni.switchTab({
  46. url:'/pages/mine/mine'
  47. });
  48. },1200);
  49. })
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss">
  55. .login-area{
  56. background-color: #F3EDE7;
  57. width: 100%;
  58. .row{
  59. margin: 15rpx auto;
  60. min-height: 150rpx;
  61. width: 80%;
  62. .input{
  63. margin-top: 30rpx;
  64. border: 1px solid gray;
  65. box-sizing: border-box;
  66. height: 100rpx;
  67. width: 100%;
  68. font-size: 30rpx;
  69. line-height: 30rpx;
  70. border-radius: 50rpx;
  71. padding: 15rpx 20rpx;
  72. }
  73. .btn{
  74. background-color: #344B44;
  75. border-radius: 50rpx;
  76. color: #ffffff;
  77. }
  78. }
  79. .register{
  80. text-align: center;
  81. font-size: 14px;
  82. color: #625D5E;
  83. }
  84. }
  85. </style>

mine register register.vue

  1. <template>
  2. <view class="register-area">
  3. <view class="row">
  4. <image src="/static/logo.png" style="width: 300rpx;height: 250rpx;margin: 0 auto;display: block;"></image>
  5. </view>
  6. <view class="row">
  7. <input type="text" class="input" placeholder="用户名 该用户名将用于账号登录" v-model="relForm.username"/>
  8. </view>
  9. <view class="row">
  10. <input type="password" class="input" placeholder="请输入登录密码" v-model="relForm.password"/>
  11. </view>
  12. <view class="row">
  13. <input type="text" class="input" placeholder="手机号" v-model="relForm.phone"/>
  14. </view>
  15. <view class="row">
  16. <input type="text" class="input" placeholder="请输入昵称" v-model="relForm.nickname"/>
  17. </view>
  18. <view class="row">
  19. <button type="default" @tap="register" class="btn">注 册</button>
  20. </view>
  21. <navigator url="/pages/mine/login/login" class="register">返回登录</navigator>
  22. </view>
  23. </template>
  24. <script>
  25. import { doRegister } from '@/api/mine/register/index.js'
  26. export default {
  27. data() {
  28. return {
  29. relForm:{
  30. phone:'',
  31. password:'',
  32. username:'',
  33. nickname:''
  34. }
  35. };
  36. },
  37. methods:{
  38. register(){
  39. doRegister(this.relForm).then(res=>{
  40. console.log(res)
  41. if(res.success){
  42. uni.showToast({
  43. title:res.message,
  44. icon:'success'
  45. })
  46. }else{
  47. uni.showToast({
  48. title:res.message,
  49. icon:'none'
  50. })
  51. }
  52. })
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss">
  58. .register-area{
  59. background-color: #F3EDE7;
  60. width: 100%;
  61. .row{
  62. margin: 10rpx auto;
  63. min-height: 120rpx;
  64. width: 90%;
  65. .input{
  66. margin-top: 20rpx;
  67. border: 1px solid gray;
  68. box-sizing: border-box;
  69. height: 100rpx;
  70. width: 100%;
  71. font-size: 30rpx;
  72. line-height: 30rpx;
  73. border-radius: 50rpx;
  74. padding: 10rpx 50rpx;
  75. }
  76. .btn{
  77. background-color: #344B44;
  78. border-radius: 50rpx;
  79. color: #ffffff;
  80. }
  81. }
  82. .register{
  83. text-align: center;
  84. font-size: 14px;
  85. color: #625D5E;
  86. }
  87. }
  88. </style>

mine mine.vue

  1. <template>
  2. <view class="info">
  3. <view class="user-info">
  4. <image :src="userInfo.icon" mode="" class="avatar"></image>
  5. <text class="nickname">{{userInfo.nickname}}</text>
  6. <text class="username">用户名:{{userInfo.username}}</text>
  7. </view>
  8. <navigator url="/pages/mine/login/login">登录</navigator>
  9. </view>
  10. </template>
  11. <script>
  12. import {getMemberInfo} from '@/api/mine/index.js'
  13. import mix from '@/minxins/index.js'
  14. export default {
  15. name:'Mine',
  16. mixins:[mix],
  17. data() {
  18. return {
  19. userInfo:null
  20. };
  21. },
  22. methods:{
  23. // getUser(){
  24. // let token = uni.getStorageSync("b-token");
  25. // if(token){
  26. // let userInfo = uni.getStorageSync("b-userInfo");
  27. // this.userInfo = userInfo;
  28. // }else{
  29. // uni.showModal({
  30. // title:'登录提示',
  31. // content:'暂未登录,是否重新登录',
  32. // success(res) {
  33. // console.log(res)
  34. // if(res.confirm){
  35. // //清空本地数据
  36. // uni.clearStorageSync();
  37. // uni.navigateTo({
  38. // url:'/pages/mine/login/login'
  39. // });
  40. // }
  41. // }
  42. // })
  43. // }
  44. // }
  45. },
  46. onLoad() {
  47. //this.getUser();
  48. },
  49. onShow() {
  50. this.checkLogin();
  51. }
  52. }
  53. </script>
  54. <style lang="scss">
  55. .info{
  56. background-color: #F3EDE7;
  57. width: 100%;
  58. .user-info{
  59. width: 100%;
  60. height: 300rpx;
  61. .avatar{
  62. width: 230rpx;
  63. height: 230rpx;
  64. border: 1px solid black;
  65. border-radius: 50%;
  66. margin-top: 40rpx;
  67. margin-left: 40rpx;
  68. }
  69. .nickname{
  70. font-size: 30px;
  71. position: absolute;
  72. top: 100rpx;
  73. left: 320rpx;
  74. color: #6C7A77;
  75. }
  76. .username{
  77. font-size: 14px;
  78. position: absolute;
  79. top: 200rpx;
  80. left: 320rpx;
  81. color: #C5C1C0;
  82. }
  83. }
  84. }
  85. </style>

order order.vue

  1. <template>
  2. <view class="order">
  3. <navigator url="/pages/order/address/address">选择收货地址</navigator>
  4. <view class="address">
  5. <text class="address-name">姓名:{{address.name}}</text>
  6. <text class="address-phone">电话:{{address.phoneNumber}}</text>
  7. <view class="address-detail">地址:{{address.province}}{{address.city}}{{address.region}}{{address.detailAddress}}</view>
  8. </view>
  9. <view class="row">id:{{orderData.orderBase && orderData.orderBase.id}}</view>
  10. <view class="row">orderSn:{{orderData.orderBase && orderData.orderBase.orderSn}}</view>
  11. <view class="row">totalAmount:{{orderData.orderBase && orderData.orderBase.totalAmount}}</view>
  12. <view class="row">status:{{orderData.orderBase && orderData.orderBase.status}}</view>
  13. <view class="order-items">
  14. <view class="order-item" v-for="(item,index) in orderData.orderItems" :key="index">
  15. <view class="item-row">id:{{item.id}}</view>
  16. <view class="item-row">orderId:{{item.orderId}}</view>
  17. <view class="item-row">orderSn:{{item.orderSn}}</view>
  18. <view class="item-row">productId:{{item.productId}}</view>
  19. <view class="item-row">productName:{{item.productName}}</view>
  20. <view class="item-row">productSn:{{item.productSn}}</view>
  21. <view class="item-row">productQuantity:{{item.productQuantity}}</view>
  22. <view class="item-row">productSkuId:{{item.productSkuId}}</view>
  23. <view class="item-row">productCategoryId:{{item.productCategoryId}}</view>
  24. <view class="item-row">realAmount:{{item.realAmount}}</view>
  25. <view class="item-row">totalPrice:{{item.totalPrice}}</view>
  26. <view class="item-row">productAttr:{{item.productAttr}}</view>
  27. </view>
  28. </view>
  29. <view>
  30. <button type="primary" @tap="save">确认付款</button>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {getPreOrderById, addConfirmOrder} from '@/api/order/index.js'
  36. export default {
  37. data() {
  38. return {
  39. orderId:null,
  40. orderData:{},
  41. address:null
  42. };
  43. },
  44. methods: {
  45. save(){
  46. addConfirmOrder({
  47. addressId: uni.getStorageSync("b-address").id,
  48. orderId: this.orderId,
  49. orderItemList: this.orderData.orderItems,
  50. payType: "",
  51. sourceType: ""
  52. }).then(res=>{
  53. console.log(res)
  54. uni.showToast({
  55. title:`付款${res.message},订单号是${res.data.orderId},订单查询码是${res.data.ordersn},总金额是${res.data.totalAmount}`,
  56. icon:'none',
  57. mask:true,
  58. duration:2000
  59. });
  60. setTimeout(()=>{
  61. uni.switchTab({
  62. url:'/pages/home/home'
  63. });
  64. },1500);
  65. })
  66. }
  67. },
  68. onLoad(options) {
  69. this.orderId = options.orderId;
  70. getPreOrderById(this.orderId).then(res=>{
  71. console.log(res);
  72. this.orderData = res.data;
  73. })
  74. },
  75. onShow() {
  76. let address = uni.getStorageSync("b-address");
  77. this.address = address;
  78. }
  79. }
  80. </script>
  81. <style lang="scss">
  82. .order{
  83. background-color: #F3EDE7;
  84. width: 100%;
  85. height: 100vh;
  86. .address{
  87. padding: 10rpx;
  88. .address-name{
  89. font-size: 40rpx;
  90. font-weight: bold;
  91. }
  92. .address-phone{
  93. font-size: 30rpx;
  94. margin-left: 100rpx;
  95. }
  96. .address-detail{
  97. font-size: 30rpx;
  98. }
  99. }
  100. .row{
  101. width: 100%;
  102. height: 30rpx;
  103. padding: 2rpx 10rpx;
  104. }
  105. .order-items{
  106. width: 90%;
  107. margin: 0 auto;
  108. background-color: #fff;
  109. border-radius: 30rpx;
  110. .order-item{
  111. min-height: 300rpx;
  112. margin-top: 20rpx;
  113. .item-row{
  114. font-size: 14px;
  115. min-height: 20rpx;
  116. line-height: 20rpx;
  117. padding: 2rpx 10rpx;
  118. margin-top: 15rpx;
  119. }
  120. }
  121. }
  122. }
  123. </style>

order address address.vue

  1. <template>
  2. <view class="address">
  3. <view class="row" v-for="item in addressList" :key="item.id" @tap="save(item)">
  4. <text class="item-name">{{item.name}}</text>
  5. <text class="item-address">{{item.province}}{{item.city}}{{item.region}}</text>
  6. <text class="item-detail">{{item.detailAddress}}</text>
  7. </view>
  8. <button type="default" @tap="add" style="background-color:#344B44; border-radius: 50rpx;color: white;">新增地址</button>
  9. </view>
  10. </template>
  11. <script>
  12. import {getAllAddress} from '@/api/order/address/index.js'
  13. import mix from '@/minxins/index.js'
  14. export default {
  15. mixins:[mix],
  16. data() {
  17. return {
  18. addressList:[]
  19. };
  20. },
  21. methods:{
  22. add(){
  23. },
  24. save(obj){
  25. uni.setStorageSync("b-address",obj);
  26. //回退一层
  27. uni.navigateBack({
  28. delta:1
  29. });
  30. }
  31. },
  32. onLoad() {
  33. //先判断是否登录
  34. if(!this.checkLogin()){
  35. uni.showToast({
  36. title:'请先登录',
  37. icon:'none'
  38. });
  39. return;
  40. }
  41. getAllAddress().then(res=>{
  42. console.log(res)
  43. this.addressList = res.data.items;
  44. })
  45. }
  46. }
  47. </script>
  48. <style lang="scss">
  49. .address{
  50. background-color: #F3EDE7;
  51. width: 100%;
  52. height: 100vh;
  53. .row{
  54. width: 100%;
  55. height: 100rpx;
  56. line-height: 100rpx;
  57. border-bottom: 1px solid #E4DED9;
  58. .item-name{
  59. padding: 20rpx;
  60. font-size: 45rpx;
  61. margin-right: 40rpx;
  62. }
  63. }
  64. }
  65. </style>

app.vue

  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. },
  6. onShow: function() {
  7. console.log('App Show')
  8. },
  9. onHide: function() {
  10. console.log('App Hide')
  11. }
  12. }
  13. </script>
  14. <style>
  15. /*每个页面公共css */
  16. * {
  17. padding: 0;
  18. margin: 0;
  19. }
  20. </style>

pages.json

  1. {
  2. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
  3. {
  4. "path" : "pages/home/home",
  5. "style" :
  6. {
  7. "navigationBarTitleText" : "首页",
  8. "enablePullDownRefresh" : false,
  9. //也可以去掉导航栏
  10. "navigationStyle": "custom"
  11. //在h5中,去掉导航栏
  12. // "h5": {
  13. // "titleNView": false
  14. // }
  15. }
  16. },
  17. {
  18. "path" : "pages/kind/kind",
  19. "style" :
  20. {
  21. "navigationBarTitleText" : "分类",
  22. "enablePullDownRefresh" : false
  23. }
  24. },
  25. {
  26. "path" : "pages/find/find",
  27. "style" :
  28. {
  29. "navigationBarTitleText" : "发现",
  30. "enablePullDownRefresh" : false
  31. }
  32. },
  33. {
  34. "path" : "pages/mine/mine",
  35. "style" :
  36. {
  37. "navigationBarTitleText" : "我的",
  38. "enablePullDownRefresh" : false
  39. }
  40. },
  41. {
  42. "path" : "pages/index/index",
  43. "style" :
  44. {
  45. "navigationBarTitleText" : "",
  46. "enablePullDownRefresh" : false
  47. }
  48. },
  49. {
  50. "path": "pages/index2/index2",
  51. "style": {
  52. "navigationBarTitleText": "首页",
  53. "enablePullDownRefresh" : false
  54. }
  55. },
  56. {
  57. "path" : "pages/kind/list/list",
  58. "style" :
  59. {
  60. "navigationBarTitleText" : "",
  61. "enablePullDownRefresh" : false
  62. }
  63. },
  64. {
  65. "path" : "pages/kind/goods/goods",
  66. "style" :
  67. {
  68. "navigationBarTitleText" : "",
  69. "enablePullDownRefresh" : true
  70. }
  71. },
  72. {
  73. "path" : "pages/info/info",
  74. "style" :
  75. {
  76. "navigationBarTitleText" : "",
  77. "enablePullDownRefresh" : false
  78. }
  79. },
  80. {
  81. "path" : "pages/mine/login/login",
  82. "style" :
  83. {
  84. "navigationBarTitleText" : "",
  85. "enablePullDownRefresh" : false
  86. }
  87. },
  88. {
  89. "path" : "pages/mine/register/register",
  90. "style" :
  91. {
  92. "navigationBarTitleText" : "",
  93. "enablePullDownRefresh" : false
  94. }
  95. },
  96. {
  97. "path" : "pages/order/order",
  98. "style" :
  99. {
  100. "navigationBarTitleText" : "",
  101. "enablePullDownRefresh" : false
  102. }
  103. },
  104. {
  105. "path" : "pages/order/address/address",
  106. "style" :
  107. {
  108. "navigationBarTitleText" : "",
  109. "enablePullDownRefresh" : false
  110. }
  111. }
  112. ],
  113. "globalStyle": {
  114. "navigationBarTextStyle": "black",
  115. "navigationBarTitleText": "uni-app",
  116. "navigationBarBackgroundColor": "#F8F8F8",
  117. "backgroundColor": "#F8F8F8"
  118. },
  119. "uniIdRouter": {},
  120. "tabBar": {
  121. "color": "#7A7E83",
  122. "selectedColor": "#3cc51f",
  123. "borderStyle": "black",
  124. "backgroundColor": "#ffffff",
  125. "list": [
  126. {
  127. "pagePath": "pages/home/home",
  128. "iconPath": "static/images/icon1.png",
  129. "selectedIconPath": "static/images/icon2.png",
  130. "text": "首页"
  131. },
  132. {
  133. "pagePath": "pages/kind/kind",
  134. "iconPath": "static/images/icon1.png",
  135. "selectedIconPath": "static/images/icon2.png",
  136. "text": "分类"
  137. },
  138. {
  139. "pagePath": "pages/find/find",
  140. "iconPath": "static/images/icon1.png",
  141. "selectedIconPath": "static/images/icon2.png",
  142. "text": "发现"
  143. },
  144. {
  145. "pagePath": "pages/mine/mine",
  146. "iconPath": "static/images/icon1.png",
  147. "selectedIconPath": "static/images/icon2.png",
  148. "text": "我的"
  149. }
  150. ]
  151. }
  152. }
  153. /*
  154. 接口文档
  155. http://leju.bufan.cloud/swagger-ui.html#/23458251433147158583614129289367102716922359/addCartUsingPOST_1
  156. */

测试

首页

 分类

 我的

 登录

 注册

二级分类

 商品列表

商品详情

 立即购买

 初始订单

 地址列表

 确认付款

以上就是全部代码了,虽然我没有按照视频教程中的内容把剩余的步骤完成。但是这个我学习的差不多了,需要吸收一下。

后续如果我还有uniapp的代码,还是会贴出来的。

感谢大家。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/652003
推荐阅读
相关标签
  

闽ICP备14008679号