vuedata.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. const app = new Vue({
  2. el:'#app',
  3. data:{
  4. group_datas: [],
  5. user_groups: [],
  6. ex: [],
  7. month: [['Jan', 'Feb', 'Mar'], ['Apr', 'May', 'Jun'], ['Jul', 'Aug', 'Sep'], ['Oct', 'Nov', 'Dec']],
  8. trends: [
  9. {
  10. group: '婚禮',
  11. data:[
  12. [{month: 'Jan', times: 782}, {month: "Feb", times: 752} , {month: 'Mar', times: 909}],
  13. [{month: 'Apr', times: 880}, {month: 'May', times: 929}, {month: "Jun", times: 883} ],
  14. [{month: 'Jul', times: 855}, {month: 'Aug', times: 776}, {month: 'Sep', times: 1020}],
  15. [{month: "Oct", times: 1206} , {month: 'Nov', times: 1042}, {month: 'Dec', times: 1051}]
  16. ]
  17. },
  18. ],
  19. keywords: [
  20. { group: "婚禮", words: ['婚禮穿搭', '婚禮穿搭男', '婚禮穿搭dcard', '婚禮穿搭禁忌', ' 婚禮穿搭褲裝', '婚禮穿搭牛仔褲', '婚禮穿搭女', '婚禮穿搭ptt', '婚禮穿搭夏天', '婚禮穿搭 冬天'] },
  21. { group: "蔬食", words: ['健康蔬食', '蔬食食譜','素食蔬食']},
  22. { group: "室內設計", words: ['室內設計風格', '室內設計圖','室內設計網站']}
  23. ],
  24. tempkeywords: [],
  25. selected: 0,
  26. json: [],
  27. },
  28. methods:{
  29. checkback(num) {
  30. if(num > 700) {
  31. return 'dark-2'
  32. } else if (num > 500) {
  33. return 'dark-1'
  34. } else if (num > 300) {
  35. return 'lighten-1'
  36. } else {
  37. return 'lighten-2'
  38. }
  39. },
  40. showModal(keywords) {
  41. $('#exampleModalCenter').modal('show');
  42. this.tempkeywords = keywords;
  43. },
  44. check(num, grpdata) {
  45. let total = 0;
  46. grpdata.trends.forEach(item => {
  47. item.forEach(single => {
  48. total += single.times;
  49. })
  50. });
  51. let threshold = total / 12;
  52. if(num > threshold) {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. },
  58. getData() {
  59. axios.get('http://www.googo.org:8050/api/group_datas/').then(res => {
  60. this.group_datas = res.data;
  61. //console.log(this.group_datas);
  62. // this.trends = this.json.filter(item => item['data_type'] === 'trends');
  63. //this.keywords = this.json.filter(item => item['data_type'] === 'suggests');
  64. });
  65. axios.get('http://www.googo.org:8050/api/user_groups/').then(res => {
  66. //console.log(res.data);
  67. this.user_groups = res.data;
  68. this.user_groups.forEach(item => {
  69. this.group_datas.forEach(d => {
  70. if(d.group_id === item.id) {
  71. d.group_chinese_name = item.group_chinese_name;
  72. }
  73. })
  74. });
  75. //console.log(this.group_datas);
  76. this.trends = this.group_datas.filter(item => item['data_type'] === 'trends');
  77. this.keywords = this.group_datas.filter(item => item['data_type'] === 'suggests');
  78. this.trends.forEach(item => {
  79. item.times = this.GetObjVal(item.data.data);
  80. let newD = [];
  81. item.times.forEach((k, i) => {
  82. if(i%3===0){
  83. newD.push([]);
  84. }
  85. const page = parseInt(i/3);
  86. newD[page].push({times:k});
  87. console.log(newD);
  88. item.final = newD;
  89. });
  90. });
  91. console.log(this.trends);
  92. console.log(this.keywords);
  93. this.user_groups.forEach(item => {
  94. this.group_datas.forEach(d => {
  95. if(d.group_id == item.id) {
  96. if(d['data_type'] == 'suggests') {
  97. item.suggests = d.data.data;
  98. console.log(item.suggests);
  99. };
  100. if(d['data_type'] == 'trends') {
  101. item.trends = d.data.data;
  102. }
  103. }
  104. })
  105. });
  106. this.user_groups.forEach(item => {
  107. if(item.trends) {
  108. const temp = this.GetObjVal(item.trends);
  109. let newD = [];
  110. temp.forEach((k, i) => {
  111. if(i%3===0){
  112. newD.push([]);
  113. }
  114. const page = parseInt(i/3);
  115. newD[page].push({times:k});
  116. item.trends = newD;
  117. });
  118. } else {
  119. item.trends = [
  120. [{times: 0}, {times: 0}, {times: 0}],
  121. [{times: 0}, {times: 0}, {times: 0}],
  122. [{times: 0}, {times: 0}, {times: 0}],
  123. [{times: 0}, {times: 0}, {times: 0}]
  124. ]
  125. }
  126. });
  127. console.log(this.user_groups);
  128. })
  129. },
  130. mergeData() {
  131. this.user_groups.forEach(item => {
  132. this.group_datas.forEach(d => {
  133. if(d['data_type'] == 'suggests') {
  134. item.suggests = d.data.data;
  135. };
  136. if(d['data_type'] == 'trends') {
  137. item.trends = d.data.data;
  138. }
  139. })
  140. });
  141. },
  142. getPack() {
  143. for(let i = 1;i < 5;i++) {
  144. axios.get(`http://www.googo.org:8050/api/group_datas/group/${i}/`).then(res => {
  145. console.log(res.data);
  146. const add = [...res.data];
  147. this.ex.push(add);
  148. //this.trends = this.json.filter(item => item['data_type'] === 'trends');
  149. //this.keywords = this.json.filter(item => item['data_type'] === 'suggests');
  150. console.log(this.ex);
  151. });
  152. }
  153. },
  154. filter() {
  155. this.user_groups .forEach(item => {
  156. this.group_datas.forEach(d => {
  157. if(d.group_id === item.id) {
  158. d.group_chinese_name = item.group_chinese_name;
  159. }
  160. })
  161. });
  162. },
  163. GetObjVal(val) {
  164. return Object.values(val);
  165. }
  166. },
  167. computed: {
  168. },
  169. created() {
  170. const d = new Date();
  171. const m = d.getMonth();
  172. if(m >= 0 && m < 3) {
  173. this.selected = 0;
  174. } else if(m >=3 && m < 6) {
  175. this.selected = 1;
  176. } else if(m >=6 && m < 9) {
  177. this.selected = 2;
  178. } else {
  179. this.selected = 3;
  180. };
  181. this.getData();
  182. //this.getPack();
  183. },
  184. mounted() {
  185. },
  186. destroyed() {
  187. },
  188. });