123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- const Mock = require('mockjs');
- var loginState="0";//登陆状态,0未登录,1管理员登陆,2商家登陆,3买家登陆
- var accountInfo=[//账号列表
- [//管理员账号
- {"name":"admin1","password":"123","mess":{"userName":"附近的拉布拉多","loginId":"admin1","password":"123"}},
- {"name":"admin2","password":"123","mess":{"userName":"附近的哈士奇","loginId":"admin2","password":"123"}},
- {"name":"admin3","password":"123","mess":{"userName":"附近的金毛","loginId":"admin3","password":"123"}},
- ],
- [//商家账号
- {"name":"shop1","password":"123","mess":{"id":1,"userName":"楚楚饰品店","loginId":"shop1","password":"123","label":"饰品"},
- "goodList":[
- {
- "id":"1",
- "coverImg":"../../../static/images/shop/coverImg2.jpg",
- "title":"精美项链定制",
- "produce":"文艺简约,气质,森系,黄金,纯银,彩金,玫瑰金,吊坠,韩版,首饰礼物,锁骨链,学生,潮流白搭",
- "price":"¥119",
- "exampleImg":[
- {name:'exampleImg21.jpg',url:'../../../static/images/shop/exampleImg21.jpg'},
- {name:'exampleImg22.jpg',url:'../../../static/images/shop/exampleImg22.jpg'},
- {name:'exampleImg23.jpg',url:'../../../static/images/shop/exampleImg23.jpg'},
- {name:'exampleImg24.jpg',url:'../../../static/images/shop/exampleImg24.jpg'},
- ],
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["黄金","白银","彩金","水晶","珍珠"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"图形",
- "list":["比翼双飞","心心相印","长命百岁","合家欢乐","福运到","守护天使"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"刻字",
- "list":["嘿,是我","小幸运","我是你爸爸","女神"]
- },
- ],
- "commentsList":[
- {
- "text":"特别美妹妹很喜欢",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地啊",
- "author":"夜凋凝"
- },
- {
- "text":"材质是真的",
- "author":"盛夏。"
- },
- ]
- },
- {
- "id":"2",
- "coverImg":"../../../static/images/shop/coverImg3.jpg",
- "title":"戒指定制",
- "produce":"北极光系列,裸钻定制,钻石,纯银,个性,学生,生日礼物,求婚,订婚,创意,网红定制刻字,日韩潮流",
- "price":"¥749",
- "exampleImg":[
- {name:'exampleImg31.jpg',url:'../../../static/images/shop/exampleImg31.jpg'},
- {name:'exampleImg32.jpg',url:'../../../static/images/shop/exampleImg32.jpg'},
- {name:'exampleImg33.jpg',url:'../../../static/images/shop/exampleImg33.jpg'},
- {name:'exampleImg34.jpg',url:'../../../static/images/shop/exampleImg34.jpg'},
- {name:'exampleImg35.jpg',url:'../../../static/images/shop/exampleImg35.jpg'},
- ],
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["黄金","白银","彩金","水晶","珍珠"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"图形",
- "list":["比翼双飞","心心相印","长命百岁","合家欢乐","福运到","守护天使"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"刻字",
- "list":["嘿,是我","小幸运","我是你爸爸","女神"]
- },
- ],
- "commentsList":[
- {
- "text":"特别美妹妹很喜欢",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地啊",
- "author":"夜凋凝"
- },
- {
- "text":"材质是真的",
- "author":"盛夏。"
- },
- ]
- },
- {
- "id":"3",
- "coverImg":"../../../static/images/shop/coverImg4.jpg",
- "title":"手链定制",
- "produce":"手工定制,字母,激光,名字,纯手工饰品,时尚,韩版,个性,收藏,包邮",
- "price":"¥158",
- "exampleImg":[
- {name:'exampleImg41.jpg',url:'../../../static/images/shop/exampleImg41.jpg'},
- {name:'exampleImg42.jpg',url:'../../../static/images/shop/exampleImg42.jpg'},
- {name:'exampleImg43.jpg',url:'../../../static/images/shop/exampleImg43.jpg'},
- {name:'exampleImg44.jpg',url:'../../../static/images/shop/exampleImg44.jpg'},
- ],
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["黄金","白银","彩金","水晶","珍珠"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"图形",
- "list":["比翼双飞","心心相印","长命百岁","合家欢乐","福运到","守护天使"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"刻字",
- "list":["嘿,是我","小幸运","我是你爸爸","女神"]
- },
- ],
- "commentsList":[
- {
- "text":"特别美妹妹很喜欢",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地啊",
- "author":"夜凋凝"
- },
- {
- "text":"材质是真的",
- "author":"盛夏。"
- },
- ]
- },
- {
- "id":"4",
- "coverImg":"../../../static/images/shop/coverImg5.jpg",
- "title":"耳坠定制",
- "produce":"手工定制,字母,激光,名字,纯手工饰品,时尚,韩版,个性,收藏,包邮",
- "price":"¥138",
- "exampleImg":[
- {name:'exampleImg51.jpg',url:'../../../static/images/shop/exampleImg51.jpg'},
- {name:'exampleImg52.jpg',url:'../../../static/images/shop/exampleImg52.jpg'},
- {name:'exampleImg53.jpg',url:'../../../static/images/shop/exampleImg53.jpg'},
- {name:'exampleImg54.jpg',url:'../../../static/images/shop/exampleImg54.jpg'},
- ],
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["黄金","白银","彩金","水晶","珍珠"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"图形",
- "list":["比翼双飞","心心相印","长命百岁","合家欢乐","福运到","守护天使"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"刻字",
- "list":["嘿,是我","小幸运","我是你爸爸","女神"]
- },
- ],
- "commentsList":[
- {
- "text":"特别美妹妹很喜欢",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地啊",
- "author":"夜凋凝"
- },
- {
- "text":"材质是真的",
- "author":"盛夏。"
- },
- ]
- },
- ]
- },
- {"name":"shop2","password":"123","mess":{"id":2,"userName":"张兴邦食品旗舰店","loginId":"shop2","password":"123","label":"食品"},
- "goodList":[
- {
- "id":"1",
- "coverImg":"../../../static/images/shop/coverImg1.jpg",//封面图片路径
- "title":"零食大礼包",
- "produce":"超多零食,送女友,超大一箱,多种类自选,小吃组合,散装混合批发,超级划算,性价比高,良心推荐,加量不加价",
- "price":"¥23.5",
- "exampleImg":[
- {name:'exampleImg11.jpg',url:'../../../static/images/shop/exampleImg11.jpg'},
- {name:'exampleImg12.jpg',url:'../../../static/images/shop/exampleImg12.jpg'},
- {name:'exampleImg13.jpg',url:'../../../static/images/shop/exampleImg13.jpg'},
- {name:'exampleImg14.jpg',url:'../../../static/images/shop/exampleImg14.jpg'},
- ],//示例图片路径
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"膨化食品类",
- "list":["虾条","薯片","鱿鱼酥","蔬菜圈","爆米花"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"凉果蜜饯类",
- "list":["话梅","凉果","蜜饯","果脯","瓜果干","酸角糕"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"肉干鱼干类",
- "list":["牛肉干","牛肉脯","猪肉粒","鱼片"]
- },
- {
- "id":3,
- "inputVisible":false,
- "type":"干果类",
- "list":["花生","瓜子","开心果","核桃仁","杏仁","榛子"]
- },
- ],
- "commentsList":[
- {
- "text":"太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦太好吃啦",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地",
- "author":"夜凋凝"
- }
- ]
- },
- ]
- },
- {"name":"shop3","password":"123","mess":{"id":3,"userName":"帕霏原创女装","loginId":"shop3","password":"123","label":"服装"},
- "goodList":[
- {
- "id":"1",
- "coverImg":"../../../static/images/shop/coverImg6.jpg",//封面图片路径
- "title":"礼服定制",
- "produce":"定制,华丽,礼服,裙,个性,蓬蓬裙,性感",
- "price":"¥923.5",
- "exampleImg":[
- {name:'exampleImg61.jpg',url:'../../../static/images/shop/exampleImg61.jpg'},
- {name:'exampleImg62.jpg',url:'../../../static/images/shop/exampleImg62.jpg'},
- {name:'exampleImg63.jpg',url:'../../../static/images/shop/exampleImg63.jpg'},
- {name:'exampleImg64.jpg',url:'../../../static/images/shop/exampleImg64.jpg'},
- {name:'exampleImg65.jpg',url:'../../../static/images/shop/exampleImg65.jpg'},
- ],//示例图片路径
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["羊毛","石棉","锦纶","涤纶","晴纶"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"颜色",
- "list":["红色","黑色","白色","紫色","粉色","绿色"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"风格",
- "list":["少女","尊贵","气质","时尚"]
- },
- ],
- "commentsList":[
- {
- "text":"质量不错",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地",
- "author":"夜凋凝"
- }
- ]
- },
- {
- "id":"2",
- "coverImg":"../../../static/images/shop/coverImg7.jpg",//封面图片路径
- "title":"夏装个性定制",
- "produce":"定制,华丽,礼服,裙,个性,蓬蓬裙,性感",
- "price":"¥923.5",
- "exampleImg":[
- {name:'exampleImg71.jpg',url:'../../../static/images/shop/exampleImg71.jpg'},
- {name:'exampleImg72.jpg',url:'../../../static/images/shop/exampleImg72.jpg'},
- {name:'exampleImg73.jpg',url:'../../../static/images/shop/exampleImg73.jpg'},
- {name:'exampleImg74.jpg',url:'../../../static/images/shop/exampleImg74.jpg'},
- ],//示例图片路径
- "tags":[//个性化元素列表
- {
- "id":0,
- "inputVisible":false,
- "type":"材质",
- "list":["羊毛","石棉","锦纶","涤纶","晴纶"]
- },
- {
- "id":1,
- "inputVisible":false,
- "type":"颜色",
- "list":["红色","黑色","白色","紫色","粉色","绿色"]
- },
- {
- "id":2,
- "inputVisible":false,
- "type":"风格",
- "list":["少女","尊贵","气质","时尚"]
- },
- ],
- "commentsList":[
- {
- "text":"质量不错",
- "author":"和牙刷私奔叻丶"
- },
- {
- "text":"不咋地",
- "author":"夜凋凝"
- }
- ]
- },
- ]
- },
- ],
- [//买家账号
- {"name":"buyer1","password":"123","mess":{"id":1,"userName":"和牙刷私奔叻丶","loginId":"buyer1","password":"123","address":"黑龙江省大庆市"}},
- {"name":"buyer2","password":"123","mess":{"id":2,"userName":"夜凋凝","loginId":"buyer2","password":"123","address":"黑龙江省鹤岗市"}},
- {"name":"buyer3","password":"123","mess":{"id":3,"userName":"盛夏。","loginId":"buyer3","password":"123","address":"四川省南充市"}},
- ],
- ];
- var shopTagList=[{id: 1, text: '饰品', value: '饰品' }, {id: 2, text: '食品', value: '食品' }, {id: 3, text: '服装', value: '服装' }]
- //登陆前检测用户名和角色是否匹配
- Mock.mock('http://www.Zhengy.com/api/judegAccount',function(options){
- var req = eval('('+options.body+')');
- var find = accountInfo[req.radio].findIndex((value,index,arr)=>{
- return value.name==req.name;
- })
- return find;
- })
- //登陆
- Mock.mock('http://www.Zhengy.com/api/login',function(options){
- var req = eval('('+options.body+')');
- var index = accountInfo[req.radio].findIndex((value,index,arr)=>{
- return value.name==req.name;
- })
- var code=accountInfo[req.radio][index].password==req.password?200:201;
- var mess=accountInfo[req.radio][index].mess;
- return {"code":code,"mess":mess};
- })
- //管理员页面
- //获取商家标签列表
- Mock.mock('http://www.Zhengy.com/api/getTagtList',function(options){
- var res = shopTagList;
- return res;
- })
- //获取账号列表
- Mock.mock('http://www.Zhengy.com/api/getAccountList',function(options){
- var req = eval('('+options.body+')');
- var res = [];
- for(var i=0,length=accountInfo[req.type].length;i<length;i++){
- res.push(accountInfo[req.type][i].mess);
- }
- return res;
- })
- //管理员对账号增删改查
- Mock.mock('http://www.Zhengy.com/api/adminHandle',function(options){
- var req = eval('('+options.body+')');
- var code = 201;
- var afterEdit = {};
- switch(req.handle){
- case "1"://添加账号
- if(req.type==1){//商家账号
- var shop={
- "name":req.mess.name,
- "password":req.mess.password,
- "mess":{
- "id":accountInfo[1][accountInfo[1].length-1].mess.id+1,
- "userName":req.mess.userName,
- "loginId":req.mess.name,
- "password":req.mess.password,
- "label":req.mess.label,
- }
- };
- accountInfo[1].push(shop);
- code=200;
- }else{//买家账号
- var buyer={
- "name":req.mess.name,
- "password":req.mess.password,
- "mess":{
- "id":accountInfo[2][accountInfo[2].length-1].mess.id+1,
- "userName":req.mess.userName,
- "loginId":req.mess.name,
- "password":req.mess.password,
- "address":req.mess.address,
- }
- }
- accountInfo[2].push(buyer);
- code=200;
- }
- break;
- case "2"://编辑账号
- var index=accountInfo[req.type].findIndex((value,index,arr)=>{
- return value.mess.id==req.mess.id;
- })
- if(req.mess.name!=""){
- accountInfo[req.type][index].name=req.mess.name;
- accountInfo[req.type][index].mess.loginId=req.mess.name;
- }
- if(req.mess.password!=""){
- accountInfo[req.type][index].password=req.mess.password;
- accountInfo[req.type][index].mess.password=req.mess.password;
- }
- if(req.mess.userName!=""){
- accountInfo[req.type][index].mess.userName=req.mess.userName;
- }
- if(req.type==1){//商家账号
- if(req.mess.label!=""){
- accountInfo[1][index].mess.label=req.mess.label;
- }
- code=200;
- }else{//买家账号
- if(req.mess.address!=""){
- accountInfo[2][index].mess.address=req.mess.address;
- }
- code=200;
- }
- afterEdit=accountInfo[req.type][index];
- break;
- default://删除账号
- var index=accountInfo[req.type].findIndex((value,index,arr)=>{
- return value.mess.id==req.mess.id;
- })
- accountInfo[req.type].splice(index,1);
- code=200;
- }
- return {"code":code,"afterEdit":afterEdit};
- })
- //商家页面
- //商家获取已上架商品列表
- Mock.mock('http://www.Zhengy.com/api/getGoodList',function(options){
- var req = eval('('+options.body+')');
- var index = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.id;
- })
- var res = accountInfo[1][index].goodList;
- return res;
- })
- //商家获取某商品详细信息
- Mock.mock('http://www.Zhengy.com/api/getGoodMess',function(options){
- var req = eval('('+options.body+')');
- var index1 = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var index2 = accountInfo[1][index1].goodList.findIndex((value,index,arr)=>{
- return value.id==req.goodId;
- })
- var res = accountInfo[1][index1].goodList[index2];
- return res;
- })
- //商家修改商品基本信息
- Mock.mock('http://www.Zhengy.com/api/changeGoodBasicMess',function(options){
- var req = eval('('+options.body+')');
- var code=201;
- var index1 = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var index2 = accountInfo[1][index1].goodList.findIndex((value,index,arr)=>{
- return value.id==req.goodId;
- })
- accountInfo[1][index1].goodList[index2].title=req.title;
- accountInfo[1][index1].goodList[index2].produce=req.produce;
- accountInfo[1][index1].goodList[index2].price=req.price;
- code=200;
- return {code:code};
- })
- //商家修改个性化案例展示图片
- Mock.mock('http://www.Zhengy.com/api/changeExampleImg',function(options){
- var req = eval('('+options.body+')');
- var code=201;
- var index1 = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var index2 = accountInfo[1][index1].goodList.findIndex((value,index,arr)=>{
- return value.id==req.goodId;
- })
- if(req.type==1){//增加
- accountInfo[1][index1].goodList[index2].exampleImg.push(req.file);
- code=200;
- }else{//删除
- var index3 = accountInfo[1][index1].goodList[index2].exampleImg.findIndex((value,index,arr)=>{
- return value.name==req.name;
- })
- accountInfo[1][index1].goodList[index2].exampleImg.splice(index3,1);
- code=200;
- }
- return {code:code,exampleImg:accountInfo[1][index1].goodList[index2].exampleImg};
- })
- //商家个性化元素管理
- Mock.mock('http://www.Zhengy.com/api/changeTags',function(options){
- var req = eval('('+options.body+')');
- var code=201;
- var index1 = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var index2 = accountInfo[1][index1].goodList.findIndex((value,index,arr)=>{
- return value.id==req.goodId;
- })
- accountInfo[1][index1].goodList[index2].tags[req.id].list=req.list;
- code=200;
- return {code:code};
- })
- //商家添加个性化元素分类
- Mock.mock('http://www.Zhengy.com/api/addGoodTags',function(options){
- var req = eval('('+options.body+')');
- var code=201;
- var index1 = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var index2 = accountInfo[1][index1].goodList.findIndex((value,index,arr)=>{
- return value.id==req.goodId;
- })
- var tag = {
- "id":accountInfo[1][index1].goodList[index2].tags[accountInfo[1][index1].goodList[index2].tags.length-1].id+1,
- "inputVisible":false,
- "type":req.type,
- "list":req.list
- }
- accountInfo[1][index1].goodList[index2].tags.push(tag);
- code=200;
- return {code:code,tag:tag}
- })
- //商家上架商品
- Mock.mock('http://www.Zhengy.com/api/addGood',function(options){
- var req = eval('('+options.body+')');
- var code=201;
- var index = accountInfo[1].findIndex((value,index,arr)=>{
- return value.mess.id==req.shopId;
- })
- var good = req.good;
- if(accountInfo[1][index].goodList.length==0){
- good.id="1";
- }else{
- good.id=accountInfo[1][index].goodList[accountInfo[1][index].goodList.length-1].id+1;
- }
- accountInfo[1][index].goodList.push(good);
- code=200;
- return {code:code,goodlist:accountInfo[1][index].goodList}
- })
|