list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-table ref="multipleTable" :data="tableData" stripe style="width: 100%;"
  5. @selection-change="handleSelectionChange" @row-click="handleExpand">
  6. <el-table-column type="expand">
  7. <template slot-scope="scope">
  8. <a v-if="scope.row.TYPE === '1'" :href="getHref(scope.row.CONTENT)" target="_blank" class="islide">
  9. <img :src="getImage(scope.row.IMAGE)" width="100px" height="100px" :alt="scope.row.TITLE">
  10. </a>
  11. <router-link v-else :to="`/article/detail/${scope.row.CONTENT}`" target="_blank" class="islide">
  12. <img :src="getImage(scope.row.IMAGE)" width="100px" height="100px" :alt="scope.row.TITLE">
  13. </router-link>
  14. </template>
  15. </el-table-column>
  16. <el-table-column type="selection" width="55"></el-table-column>
  17. <el-table-column label="Ad Title" prop="TITLE" width="250"> <!-- 广告标题 -->
  18. <template slot-scope="scope">
  19. <el-tag type="" size="small" class="no-border">{{scope.row.TITLE}}</el-tag>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="Ad Location" width="150"> <!-- 广告位 -->
  23. <template slot-scope="scope">
  24. <el-tag type="warning" size="small" class="no-border">{{allData.allLocation[scope.row.LID].LOCATION_NAME}}</el-tag>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="Type"> <!-- 类型 -->
  28. <template slot-scope="scope">
  29. <template v-if="scope.row.TYPE === '1'">
  30. <el-tag type="success">External Links</el-tag> <!-- 外链 -->
  31. </template>
  32. <template v-else-if="scope.row.TYPE === '2'">
  33. <el-tag>Article</el-tag> <!-- 文章 -->
  34. </template>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="Content" prop="CONTENT" width="120">
  38. <template slot-scope="scope">
  39. <div v-if="scope.row.TYPE === '1'">
  40. <el-link type="primary" target="_blank" :href="getHref(scope.row.CONTENT)">{{ scope.row.CONTENT }}</el-link>
  41. </div><!-- 链接 -->
  42. <div v-else-if="scope.row.TYPE === '2'">
  43. <router-link :to="`/article/detail/${scope.row.CONTENT}`" target="_blank" style="cursor: pointer;">{{ getContent(scope.row.CONTENT) }}</router-link>
  44. </div><!-- 文章 -->
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="Sort" width="100"> <!-- 排序 -->
  48. <template slot-scope="scope">
  49. <el-input v-model="scope.row.SORT" min="0" max="99" @change="handleChangeSort(scope.row, scope.row.SORT)"
  50. @click.native.stop=""></el-input>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="Creator"> <!-- 创建人 -->
  54. <template slot-scope="scope">
  55. {{scope.row.CREATE_ADMIN_NAME}}
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="Created Time" width="180"> <!-- 创建时间 -->
  59. <template slot-scope="scope">
  60. {{tool.formatDate(scope.row.CREATED_AT)}}
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="Modified By"> <!-- 修改人 -->
  64. <template slot-scope="scope">
  65. {{scope.row.UPDATE_ADMIN_NAME}}
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="Modified Time" width="180"> <!-- 修改时间 -->
  69. <template slot-scope="scope">
  70. {{tool.formatDate(scope.row.UPDATED_AT)}}
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="Status"> <!-- 状态 -->
  74. <template slot-scope="scope">
  75. <div v-if="scope.row.STATUS === '1'">Show</div>
  76. <div v-else>Hide</div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column fixed="right" label="Action" width="180"> <!-- 操作 -->
  80. <template slot-scope="scope">
  81. <el-dropdown size="small" trigger="click" v-if="permission.hasPermission(`ad/ad-delete`) || permission.hasPermission(`ad/edit`)">
  82. <el-button type="primary" size="small" @click.stop="">
  83. Action<i class="el-icon-arrow-down el-icon--right"></i>
  84. </el-button>
  85. <el-dropdown-menu slot="dropdown">
  86. <el-dropdown-item command="edit" @click.native="handleEdit(scope.row)" v-if="permission.hasPermission(`ad/edit`)">Edit</el-dropdown-item>
  87. <el-dropdown-item command="delete" @click.native="handleDelete(scope.row)" v-if="permission.hasPermission(`ad/ad-delete`)">Delete</el-dropdown-item>
  88. <el-dropdown-item command="hide" @click.native="handleHide(scope.row)" v-if="permission.hasPermission(`ad/ad-hide`)">Hide</el-dropdown-item>
  89. <el-dropdown-item command="un-hide" @click.native="handleUnHide(scope.row)" v-if="permission.hasPermission(`ad/ad-un-hide`)">UnHide</el-dropdown-item>
  90. </el-dropdown-menu>
  91. </el-dropdown>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <div class="white-box-footer">
  96. <el-dropdown size="small" trigger="click" v-if="permission.hasPermission(`ad/ad-delete`)">
  97. <el-button type="primary" size="small">
  98. Selected data<!--所选数据--><i class="el-icon-arrow-down el-icon--right"></i>
  99. </el-button>
  100. <el-dropdown-menu slot="dropdown">
  101. <el-dropdown-item command="delete" @click.native="handleMuliDel()">Delete</el-dropdown-item>
  102. <el-dropdown-item command="hide" @click.native="handleMultiHide()">Hide</el-dropdown-item>
  103. <el-dropdown-item command="un-hide" @click.native="handleMultiUnHide()">UnHide</el-dropdown-item>
  104. </el-dropdown-menu>
  105. </el-dropdown>
  106. <el-button type="primary" size="small" @click="handleAdd" icon="el-icon-plus" v-if="permission.hasPermission(`ad/add`)">Add Ad</el-button>
  107. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
  108. </div>
  109. </div>
  110. </div>
  111. </template>
  112. <script>
  113. import Vue from 'vue'
  114. import network from '@/utils/network'
  115. import tool from '@/utils/tool'
  116. import store from '@/utils/vuexStore'
  117. import permission from '@/utils/permission'
  118. import Pagination from '@/components/Pagination'
  119. import {SERVER_API_HTTP_TYPE,SERVER_API_DOMAIN} from '@/utils/config'
  120. import article from "../article";
  121. export default {
  122. name: 'ad_list',
  123. components: {Pagination},
  124. mounted () {
  125. this.getData()
  126. },
  127. data () {
  128. return {
  129. allData: null,
  130. tableData: null,
  131. loading: true,
  132. multipleSelection: [],
  133. currentPage: 1,
  134. totalPages: 1,
  135. totalCount: 1,
  136. pageSize: 20,
  137. tool: tool,
  138. permission: permission,
  139. allArticle: [],
  140. }
  141. },
  142. methods: {
  143. handleExpand (row, event, column) {
  144. this.$refs.multipleTable.toggleRowExpansion(row)
  145. },
  146. handleSelectionChange (val) {
  147. this.multipleSelection = val
  148. },
  149. handleCurrentChange (page) {
  150. this.getData(page, this.pageSize)
  151. },
  152. handleSizeChange (pageSize) {
  153. this.getData(this.currentPage, pageSize)
  154. },
  155. handleAdd () {
  156. this.$router.push({path: `/ad/add`})
  157. },
  158. handleEdit (row) {
  159. this.$router.push({path: `/ad/edit/${row.ID}`})
  160. },
  161. handleDelete (row) {
  162. this.delData(row.ID)
  163. },
  164. handleHide (row) {
  165. this.hideData(row.ID)
  166. },
  167. handleUnHide(row) {
  168. this.unHideData(row.ID)
  169. },
  170. handleMuliDel () {
  171. this.delData()
  172. },
  173. handleMultiHide () {
  174. this.hideData()
  175. },
  176. handleMultiUnHide () {
  177. this.unHideData()
  178. },
  179. handleChangeSort (row, sort) {
  180. network.getData('/ad/sort', {id: row.ID, sort: sort}).then(response => {
  181. this.getData(this.currentPage, this.pageSize)
  182. }).catch(response => {
  183. })
  184. },
  185. getData (page, pageSize) {
  186. let obj = this
  187. network.getPageData(this, `ad/list/${this.$route.params.lid}`, page, pageSize, null, function (response) {
  188. obj.allData = response
  189. obj.allArticle = response.allArticle
  190. })
  191. },
  192. delData (id = null) {
  193. let obj = this
  194. obj.$confirm('Are you sure to delete the selected data?', 'Notice', { // 确定删除选定的数据?
  195. confirmButtonText: 'confirm', // 确定
  196. cancelButtonText: 'cancel', // 取消
  197. type: 'warning'
  198. }).then(() => {
  199. let selectedIds = []
  200. if (id === null) {
  201. for (let val of obj.multipleSelection) {
  202. selectedIds.push(val.ID)
  203. }
  204. } else {
  205. selectedIds.push(id)
  206. }
  207. return network.postData(`ad/ad-delete`, {
  208. selected: selectedIds
  209. })
  210. }).then(response => {
  211. this.$message({
  212. message: response,
  213. type: 'success'
  214. })
  215. obj.getData(obj.currentPage, obj.pageSize)
  216. }).catch(response => {
  217. })
  218. },
  219. hideData (id = null) {
  220. let obj = this
  221. obj.$confirm('Are you sure to hide the selected data?', 'Notice', { // 确定删除选定的数据?
  222. confirmButtonText: 'confirm', // 确定
  223. cancelButtonText: 'cancel', // 取消
  224. type: 'warning'
  225. }).then(() => {
  226. let selectedIds = []
  227. if (id === null) {
  228. for (let val of obj.multipleSelection) {
  229. selectedIds.push(val.ID)
  230. }
  231. } else {
  232. selectedIds.push(id)
  233. }
  234. return network.postData(`ad/ad-hide`, {
  235. selected: selectedIds
  236. })
  237. }).then(response => {
  238. this.$message({
  239. message: response,
  240. type: 'success'
  241. })
  242. obj.getData(obj.currentPage, obj.pageSize)
  243. }).catch(response => {
  244. })
  245. },
  246. unHideData (id = null) {
  247. let obj = this
  248. obj.$confirm('Are you sure to un-hide the selected data?', 'Notice', { // 确定删除选定的数据?
  249. confirmButtonText: 'confirm', // 确定
  250. cancelButtonText: 'cancel', // 取消
  251. type: 'warning'
  252. }).then(() => {
  253. let selectedIds = []
  254. if (id === null) {
  255. for (let val of obj.multipleSelection) {
  256. selectedIds.push(val.ID)
  257. }
  258. } else {
  259. selectedIds.push(id)
  260. }
  261. return network.postData(`ad/ad-un-hide`, {
  262. selected: selectedIds
  263. })
  264. }).then(response => {
  265. this.$message({
  266. message: response,
  267. type: 'success'
  268. })
  269. obj.getData(obj.currentPage, obj.pageSize)
  270. }).catch(response => {
  271. })
  272. },
  273. getImage(imageUrl) {
  274. return imageUrl.indexOf('http') > -1 ? imageUrl : SERVER_API_HTTP_TYPE + SERVER_API_DOMAIN + '/uploads/' + imageUrl;
  275. },
  276. getContent(aid) {
  277. let titles = this.allArticle.filter(article => article.ID === aid).map(article => article.TITLE);
  278. return titles.length > 0 ? titles[0] : aid;
  279. },
  280. getHref(link) {
  281. return link.indexOf('http') > -1 ? link : 'http://' + link;
  282. },
  283. }
  284. }
  285. </script>
  286. <style scoped>
  287. </style>