Skip to content

Commit

Permalink
remove props map function, fix format source to data in init
Browse files Browse the repository at this point in the history
  • Loading branch information
lpreterite committed Jun 30, 2017
1 parent f74a9a7 commit 5a899ee
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 34 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var vm = new Vue({
<vue-sina-emotion
:source="emotions"
:map="map"
@click="emotion=arguments[0].phrase">
@change="emotion=arguments[0].phrase">
</vue-sina-emotion>
</div>
Expand Down Expand Up @@ -78,7 +78,7 @@ more see **example**

## Dev

``` bash
```
# install dependencies
npm install
Expand All @@ -90,4 +90,9 @@ npm run build
# run mock serve
npm run mock
```
```

## Change Log

### 0.1.1
remove props map function, fix format source to data in init
2 changes: 1 addition & 1 deletion build/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ module.exports = {
performance: {
hints: false
},
devtool: '#eval-source-map'
devtool: 'source-map'
}
17 changes: 13 additions & 4 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ options.module.rules.unshift({
'js': 'babel-loader',
'css': ExtractTextPlugin.extract({
use: 'css-loader',
fallback: 'vue-style-loader'
fallback: {
loader: 'vue-style-loader',
options: {sourceMap: false}
}
}),
'scss': ExtractTextPlugin.extract({
use: 'css-loader!sass-loader',
fallback: 'vue-style-loader'
use: [
{ loader: 'css-loader', options: {sourceMap: false} },
{ loader: 'sass-loader', options: {sourceMap: false} }
],
fallback: {
loader: 'vue-style-loader',
options: {sourceMap: false}
}
})
}
}
Expand All @@ -29,7 +38,7 @@ options.plugins = [
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
sourceMap: false,
compress: {
warnings: false
}
Expand Down
3 changes: 2 additions & 1 deletion dist/vue-sina-emotion.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/vue-sina-emotion.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-sina-emotion.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div id="app">
<h1>{{ title }}</h1>
<p>{{ emotion }} <img :src="emotionsMap[emotion]" alt=""></p>
<vue-sina-emotion :source="emotions" @click="emotion=arguments[0].phrase" :map="map"></vue-sina-emotion>
<vue-sina-emotion :source="emotions" @change="emotion=arguments[0].phrase"></vue-sina-emotion>
</div>
<script src="/vendor/build.js"></script>
</body>
Expand Down
8 changes: 5 additions & 3 deletions example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ var vm = new Vue({
emotionsMap: {}
}
},
methods: {
map: function(data){
this.emotionsMap = data;
watch: {
emotions(val){
var map = {};
val.forEach(emotion=>map[emotion.value]=emotion.url);
this.emotionsMap = map;
}
}
})
3 changes: 2 additions & 1 deletion mock/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const router = jsonServer.router(path.join(__dirname, './db.json'));
const middlewares = jsonServer.defaults();
const emotions = require('./emotions.json');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-sina-emotion",
"description": "新浪表情面板的vue组件",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/vue-sina-emotion.js",
"author": "packy <[email protected]>",
"keywords": [
Expand Down
9 changes: 0 additions & 9 deletions src/handle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import axios from 'axios';

export function getEmotions(source, language){
return axios.get('https://api.weibo.com/2/emotions.json?callback=?', {params:{
source,
language
}});
};

export function hashEmotions(emotions){
var groups = {},
categories = [],
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import VueSinaEmotion from './vue-sina-emotion';
import { hashEmotions, paginator } from './handle';
export { VueSinaEmotion, hashEmotions, paginator };
export default VueSinaEmotion;
18 changes: 9 additions & 9 deletions src/vue-sina-emotion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</header>
<div class="sina-emotion-panel__content">
<template v-for="emotion in emotions.data">
<a href="#" @click.prevent.stop="$emit('click', emotion)">
<a href="#" @click.prevent.stop="$emit('change', emotion)">
<img :src="emotion.icon" :alt="emotion.phrase">
</a>
</template>
Expand Down Expand Up @@ -82,26 +82,21 @@
}
</style>
<script>
import { hashEmotions, getEmotions, paginator } from './handle';
import { hashEmotions, paginator } from './handle';
export default {
name: 'vue-sina-emotion',
props: {
source: Array,
pageRows: {
type: Number,
default: 0
},
map: {
type: Function,
default: function(){}
}
},
watch: {
source(val){
this.storage = hashEmotions(val);
this.categories = paginator(this.categories.currentPage, this.storage.categories, {pageRow: 5});
this.emotions = paginator(this.emotions.currentPage, this.storage.groups[this.currentCate] || []);
this.map(this.storage.map);
},
currentCate(val){
this.emotions = paginator(this.emotions.currentPage, this.storage.groups[val] || []);
Expand All @@ -114,7 +109,7 @@ export default {
}
},
data(){
return {
const data = {
storage: {},
emotions: {
pageRow: 0,
Expand All @@ -133,7 +128,12 @@ export default {
data: []
},
currentCate: '默认'
}
};
data.storage = hashEmotions(this.source);
data.categories = paginator(data.categories.currentPage, data.storage.categories, {pageRow: 5});
data.emotions = paginator(data.emotions.currentPage, data.storage.groups[data.currentCate] || []);
return data;
},
methods:{
next(){
Expand Down

0 comments on commit 5a899ee

Please sign in to comment.