Index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <div class="hello">
  3. <Header> </Header>
  4. <el-container class="container-narrow">
  5. <el-row class="masthead">
  6. <div class="logo-title ">
  7. <h2 class="muted"><img src="static/logo/b_64.png" style="width:50px;height:50px;margin-bottom:-10px;" alt="">ShowDoc</h2>
  8. </div>
  9. <div class="header-btn-group pull-right">
  10. <el-button type="text" @click="feedback">{{$t("feedback")}}</el-button>
  11. <router-link to="/team/index" >&nbsp;&nbsp;&nbsp;{{$t('team_mamage')}}</router-link>
  12. <router-link to="/admin/index" v-if="isAdmin">&nbsp;&nbsp;&nbsp;{{$t('background')}}</router-link>
  13. &nbsp;&nbsp;&nbsp;
  14. <el-dropdown @command="dropdown_callback">
  15. <span class="el-dropdown-link">
  16. {{$t("more")}}<i class="el-icon-arrow-down el-icon--right"></i>
  17. </span>
  18. <el-dropdown-menu slot="dropdown">
  19. <el-dropdown-item><router-link to="/user/setting">{{$t("personal_setting")}}</router-link></el-dropdown-item>
  20. <el-dropdown-item :command="logout">{{$t("logout")}}</el-dropdown-item>
  21. </el-dropdown-menu>
  22. </el-dropdown>
  23. </div>
  24. </el-row>
  25. </el-container>
  26. <el-container class="container-narrow">
  27. <div class="container-thumbnails">
  28. <ul class="thumbnails" id="item-list" v-if="itemList">
  29. <li class=" text-center" v-for="item in itemList"
  30. v-dragging="{ item: item, list: itemList, group: 'item' }"
  31. >
  32. <router-link class="thumbnail item-thumbnail" :to="'/' + (item.item_domain ? item.item_domain:item.item_id )" title="">
  33. <span class="item-setting " @click.prevent="click_item_setting(item.item_id)" :title="$t('item_setting')" >
  34. <i class="el-icon-setting"></i>
  35. </span>
  36. <span class="item-top " @click.prevent="click_item_top(item.item_id,item.top)" :title="item.top ? $t('cancel_item_top'):$t('item_top')" >
  37. <i :class="item_top_class(item.top)"></i>
  38. </span>
  39. <p class="my-item">{{item.item_name}}</p>
  40. </router-link>
  41. </li>
  42. <li class=" text-center" >
  43. <router-link class="thumbnail item-thumbnail" to="/item/add" title="">
  44. <p class="my-item">{{$t('new_item')}}<i class="el-icon-plus"></i></p>
  45. </router-link>
  46. </li>
  47. </ul>
  48. </div>
  49. </el-container>
  50. <Footer> </Footer>
  51. </div>
  52. </template>
  53. <style scoped>
  54. .container-narrow{
  55. margin: 0 auto;
  56. max-width: 700px;
  57. }
  58. .masthead{
  59. width: 100%;
  60. margin-top: 30px;
  61. }
  62. .header-btn-group{
  63. margin-top: -38px;
  64. }
  65. .logo-title{
  66. margin-left: 0px;
  67. }
  68. .container-thumbnails{
  69. margin: 0 auto;
  70. margin-top: 30px;
  71. max-width: 700px;
  72. }
  73. .my-item{
  74. margin: 40px 5px;
  75. }
  76. .thumbnails>li {
  77. float: left;
  78. margin-bottom: 20px;
  79. margin-left: 20px;
  80. }
  81. .thumbnails li a{
  82. color: #777;
  83. font-weight: bold;
  84. height: 100px;
  85. width: 180px;
  86. }
  87. .thumbnails li a:hover,
  88. .thumbnails li a:focus{
  89. border-color:#f2f5e9;
  90. -webkit-box-shadow:none;
  91. box-shadow:none;
  92. text-decoration: none;
  93. background-color: #f2f5e9;
  94. }
  95. .thumbnail {
  96. display: block;
  97. padding: 4px;
  98. line-height: 20px;
  99. border: 1px solid #ddd;
  100. -webkit-border-radius: 4px;
  101. -moz-border-radius: 4px;
  102. border-radius: 4px;
  103. -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  104. -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  105. box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  106. -webkit-transition: all .2s ease-in-out;
  107. -moz-transition: all .2s ease-in-out;
  108. -o-transition: all .2s ease-in-out;
  109. transition: all .2s ease-in-out;
  110. list-style: none;
  111. }
  112. .item-setting{
  113. float:right;
  114. margin-right:15px;
  115. margin-top:5px;
  116. display: none;
  117. }
  118. .item-top{
  119. float:right;
  120. margin-right:5px;
  121. margin-top:5px;
  122. display: none;
  123. }
  124. .thumbnails li a i{
  125. color: #777;
  126. font-weight: bold;
  127. margin-left: 5px;
  128. }
  129. </style>
  130. <script>
  131. if (typeof window !== 'undefined') {
  132. var $s = require('scriptjs');
  133. }
  134. export default {
  135. data() {
  136. return {
  137. currentDate: new Date(),
  138. itemList:{},
  139. isAdmin:false
  140. };
  141. },
  142. methods:{
  143. get_item_list(){
  144. var that = this ;
  145. var url = DocConfig.server+'/api/item/myList';
  146. var params = new URLSearchParams();
  147. that.axios.get(url, params)
  148. .then(function (response) {
  149. if (response.data.error_code === 0 ) {
  150. //that.$message.success("加载成功");
  151. var json = response.data.data ;
  152. that.itemList = json ;
  153. that.bind_item_even();
  154. }else{
  155. that.$alert(response.data.error_message);
  156. }
  157. });
  158. },
  159. feedback(){
  160. if (DocConfig.lang =='en') {
  161. window.open('https://github.com/star7th/showdoc/issues');
  162. }else{
  163. var msg = "你正在使用免费开源版showdoc,如有问题或者建议,请到github提issue:";
  164. msg += "<a href='https://github.com/star7th/showdoc/issues' target='_blank'>https://github.com/star7th/showdoc/issues</a><br>";
  165. msg += "如果你觉得showdoc好用,不妨给开源项目点一个star。良好的关注度和参与度有助于开源项目的长远发展。";
  166. this.$alert(msg, {
  167. dangerouslyUseHTMLString: true
  168. });
  169. }
  170. },
  171. item_top_class(top){
  172. if (top) {
  173. return 'el-icon-arrow-down';
  174. };
  175. return 'el-icon-arrow-up';
  176. },
  177. bind_item_even(){
  178. //这里偷个懒,直接用jquery来操作DOM。因为老版本的代码就是基于jquery的,所以复制过来稍微改下
  179. $s(["static/jquery.min.js"],()=>{
  180. //当鼠标放在项目上时将浮现设置和置顶图标
  181. $(".item-thumbnail").mouseover(function(){
  182. $(this).find(".item-setting").show();
  183. //$(this).find(".item-top").show();
  184. //$(this).find(".item-down").show();
  185. });
  186. //当鼠标离开项目上时将隐藏设置和置顶图标
  187. $(".item-thumbnail").mouseout(function(){
  188. $(this).find(".item-setting").hide();
  189. $(this).find(".item-top").hide();
  190. $(this).find(".item-down").hide();
  191. });
  192. });
  193. },
  194. //进入项目设置页
  195. click_item_setting(item_id){
  196. this.$router.push({path:'/item/setting/'+item_id});
  197. },
  198. click_item_top(item_id ,old_top){
  199. if (old_top) {
  200. var action = 'cancel';
  201. }else{
  202. var action = 'top';
  203. }
  204. var that = this ;
  205. var url = DocConfig.server+'/api/item/top';
  206. var params = new URLSearchParams();
  207. params.append('action', action);
  208. params.append('item_id', item_id);
  209. that.axios.post(url, params)
  210. .then(function (response) {
  211. if (response.data.error_code === 0 ) {
  212. that.get_item_list();
  213. }else{
  214. that.$alert(response.data.error_message);
  215. }
  216. });
  217. },
  218. logout(){
  219. var that = this ;
  220. var url = DocConfig.server+'/api/user/logout';
  221. var params = new URLSearchParams();
  222. that.axios.get(url, params)
  223. .then(function (response) {
  224. if (response.data.error_code === 0 ) {
  225. that.$router.push({
  226. path: '/'
  227. });
  228. }else{
  229. that.$alert(response.data.error_message);
  230. }
  231. });
  232. },
  233. user_info(){
  234. var that = this ;
  235. this.get_user_info(function(response){
  236. if (response.data.error_code === 0 ) {
  237. if (response.data.data.groupid == 1 ) {
  238. that.isAdmin = true ;
  239. };
  240. }
  241. });
  242. },
  243. dropdown_callback(data){
  244. if (data) {
  245. data();
  246. };
  247. },
  248. sort_item(data){
  249. var that = this ;
  250. var url = DocConfig.server+'/api/item/sort';
  251. var params = new URLSearchParams();
  252. params.append('data', JSON.stringify(data));
  253. that.axios.post(url, params)
  254. .then(function (response) {
  255. if (response.data.error_code === 0 ) {
  256. //that.get_item_list();
  257. //window.location.reload();
  258. }else{
  259. that.$alert(response.data.error_message,'',{
  260. callback:function(){
  261. window.location.reload();
  262. }
  263. });
  264. }
  265. });
  266. },
  267. dragging(){
  268. this.$dragging.$off('dragged',true);
  269. this.$dragging.$on('dragged', ({ value }) => {
  270. //console.log(value);
  271. let data = {};
  272. for (var i = 0; i < value['list'].length; i++) {
  273. let key = value['list'][i]['item_id'] ;
  274. data[key] = i + 1 ;
  275. };
  276. this.sort_item(data);
  277. })
  278. }
  279. },
  280. mounted () {
  281. this.get_item_list();
  282. this.user_info();
  283. this.dragging();
  284. },
  285. beforeDestroy(){
  286. this.$message.closeAll();
  287. /*去掉添加的背景色*/
  288. document.body.removeAttribute("class","grey-bg");
  289. }
  290. }
  291. </script>