joway 2 lat temu
rodzic
commit
f9123b7123
7 zmienionych plików z 289 dodań i 57 usunięć
  1. 22 0
      src/api/ad.js
  2. 8 2
      src/lang/en.js
  3. 8 1
      src/lang/zh.js
  4. 2 2
      src/router/index.js
  5. 6 51
      src/views/ad/index.vue
  6. 242 0
      src/views/ad/list.vue
  7. 1 1
      vue.config.js

+ 22 - 0
src/api/ad.js

@@ -6,3 +6,25 @@ export function fetchList(query) {
     method: 'get'
   })
 }
+
+export function fetchAdList(query) {
+  return request({
+    url: '/v1/ad/list/' + query.adId.ID,
+    method: 'get',
+    params: {
+      page: query.page,
+      pageSize: query.pageSize
+    }
+  })
+}
+
+export function fetchChangeSort(query) {
+  return request({
+    url: '/v1/ad/sort',
+    method: 'get',
+    params: {
+      id: query.id,
+      sort: query.sort
+    }
+  })
+}

+ 8 - 2
src/lang/en.js

@@ -90,8 +90,14 @@ export default {
     externalLinks: 'External Links',
     article: 'Article',
     slideshow: 'Slideshow',
-    image: 'Image'
-
+    image: 'Image',
+    adTitle: 'Ad Title',
+    content: 'Content',
+    sort: 'Sort',
+    modifiedBy: 'Modified By',
+    modifiedTime: 'Modified Time',
+    status: 'Status',
+    adLocation: 'Ad Location'
   },
   documentation: {
     documentation: 'Documentation',

+ 8 - 1
src/lang/zh.js

@@ -90,7 +90,14 @@ export default {
     externalLinks: '外部链接',
     article: '文章',
     slideshow: '幻灯',
-    image: '图片'
+    image: '图片',
+    adTitle: '标题',
+    content: '内容',
+    sort: '排序',
+    modifiedBy: '更新人',
+    modifiedTime: '更新时间',
+    status: '类型',
+    adLocation: '位置'
   },
   documentation: {
     documentation: '文档',

+ 2 - 2
src/router/index.js

@@ -151,10 +151,10 @@ export const asyncRoutes = [
         meta: { title: 'adLocation', icon: 'user', noCache: true }
       },
       {
-        path: 'list/:id(\\d+)',
+        path: 'list/:ID(\\w+)',
         component: () => import('@/views/ad/list'),
         name: 'Ad List',
-        meta: { title: 'adList', noCache: true, activeMenu: '/ad/list' },
+        meta: { title: 'adList', noCache: true, activeMenu: '/ad/location' },
         hidden: true
       }
     ]

+ 6 - 51
src/views/ad/index.vue

@@ -8,7 +8,6 @@
       fit
       highlight-current-row
       style="width: 100%;"
-      @sort-change="sortChange"
     >
       <el-table-column :label="$t('ad.ad')" prop="id" align="center" :class-name="getSortClass('id')">
         <template slot-scope="{row}">
@@ -45,56 +44,16 @@
           <el-button type="primary" size="mini" @click="handleView(row)">
             {{ $t('ad.view') }}
           </el-button>
+          <!-- <router-link :to="'/ad/list/'+ row.id" class="link-type">
+            <el-button type="primary" size="small" icon="el-icon-edit">
+              {{ $t('ad.view') }}
+            </el-button>
+          </router-link> -->
         </template>
       </el-table-column>
     </el-table>
 
     <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
-
-    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
-      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
-        <el-form-item :label="$t('table.type')" prop="type">
-          <el-select v-model="temp.type" class="filter-item" placeholder="Please select">
-            <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
-          </el-select>
-        </el-form-item>
-        <el-form-item :label="$t('table.date')" prop="timestamp">
-          <el-date-picker v-model="temp.timestamp" type="datetime" placeholder="Please pick a date" />
-        </el-form-item>
-        <el-form-item :label="$t('table.title')" prop="title">
-          <el-input v-model="temp.title" />
-        </el-form-item>
-        <el-form-item :label="$t('table.status')">
-          <el-select v-model="temp.status" class="filter-item" placeholder="Please select">
-            <el-option v-for="item in statusOptions" :key="item" :label="item" :value="item" />
-          </el-select>
-        </el-form-item>
-        <el-form-item :label="$t('table.importance')">
-          <el-rate v-model="temp.importance" :colors="['#99A9BF', '#F7BA2A', '#FF9900']" :max="3" style="margin-top:8px;" />
-        </el-form-item>
-        <el-form-item :label="$t('table.remark')">
-          <el-input v-model="temp.remark" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="Please input" />
-        </el-form-item>
-      </el-form>
-      <div slot="footer" class="dialog-footer">
-        <el-button @click="dialogFormVisible = false">
-          {{ $t('table.cancel') }}
-        </el-button>
-        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
-          {{ $t('table.confirm') }}
-        </el-button>
-      </div>
-    </el-dialog>
-
-    <el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
-      <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
-        <el-table-column prop="key" label="Channel" />
-        <el-table-column prop="pv" label="Pv" />
-      </el-table>
-      <span slot="footer" class="dialog-footer">
-        <el-button type="primary" @click="dialogPvVisible = false">{{ $t('table.confirm') }}</el-button>
-      </span>
-    </el-dialog>
   </div>
 </template>
 
@@ -140,11 +99,7 @@ export default {
       listLoading: true,
       listQuery: {
         page: 1,
-        limit: 20,
-        importance: undefined,
-        title: undefined,
-        type: undefined,
-        sort: '+id'
+        limit: 20
       },
       importanceOptions: [1, 2, 3],
       calendarTypeOptions,

+ 242 - 0
src/views/ad/list.vue

@@ -0,0 +1,242 @@
+<template>
+  <div class="app-container">
+    <el-table
+      :key="tableKey"
+      v-loading="listLoading"
+      :data="list"
+      border
+      fit
+      highlight-current-row
+      style="width: 100%;"
+    >
+      <el-table-column :label="$t('ad.adTitle')" prop="id" align="center" :class-name="getSortClass('id')">
+        <template slot-scope="{row}">
+          <span>{{ row.TITLE }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.adLocation')" prop="id" align="center" :class-name="getSortClass('id')">
+        <template :value="{allLocation}">
+          <span>{{ allLocation.LOCATION_NAME }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.type')" align="center"> <!-- 类型 -->
+        <template slot-scope="{row}">
+          <template v-if="row.TYPE === '1'">
+            <el-tag type="success">External Links</el-tag> <!-- 外链 -->
+          </template>
+          <template v-else-if="row.TYPE === '2'">
+            <el-tag>Article</el-tag> <!-- 文章 -->
+          </template>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.content')" prop="id" align="center" :class-name="getSortClass('id')">
+        <template slot-scope="{row}">
+          <div v-if="row.TYPE === '1'">
+            <el-link type="primary" target="_blank" :href="getHref(row.CONTENT)">{{ row.CONTENT }}</el-link>
+          </div><!-- 链接 -->
+          <div v-else-if="row.TYPE === '2'">
+            <router-link :to="`/article/detail/${row.CONTENT}`" target="_blank" style="cursor: pointer;">{{ getContent(row.CONTENT) }}</router-link>
+          </div><!-- 文章 -->
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.sort')" prop="id" align="center" :class-name="getSortClass('id')">
+        <template slot-scope="{row}">
+          <el-input
+            v-model="row.SORT"
+            min="0"
+            max="99"
+            @change="handleChangeSort(row.ID, row.SORT)"
+            @click.native.stop=""
+          />
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.creator')" prop="id" align="center" :class-name="getSortClass('id')">
+        <template slot-scope="{row}">
+          <span>{{ row.CREATE_ADMIN_NAME }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.createTime')" align="center">
+        <template slot-scope="{row}">
+          <span>{{ row.CREATED_AT | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.modifiedBy')" prop="id" align="center" width="80" :class-name="getSortClass('id')">
+        <template slot-scope="{row}">
+          <span>{{ row.UPDATE_ADMIN_NAME }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.modifiedTime')" align="center">
+        <template slot-scope="{row}">
+          <span>{{ row.UPDATED_AT | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.status')" align="center"> <!-- 类型 -->
+        <template slot-scope="{row}">
+          <template v-if="row.STATUS === '1'">
+            <el-tag type="success">show</el-tag> <!-- 外链 -->
+          </template>
+          <template v-else>
+            <el-tag>hide</el-tag> <!-- 文章 -->
+          </template>
+        </template>
+      </el-table-column>
+      <el-table-column :label="$t('ad.action')" align="center" class-name="small-padding fixed-width" />
+    </el-table>
+    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
+  </div>
+</template>
+
+<script>
+import { fetchAdList, fetchChangeSort } from '@/api/ad'
+import waves from '@/directive/waves' // waves directive
+import { parseTime } from '@/utils'
+import Pagination from '@/components/Pagination' // secondary package based on el-pagination
+
+const calendarTypeOptions = [
+  { key: 'CN', display_name: 'China' },
+  { key: 'US', display_name: 'USA' }
+]
+
+// arr to obj, such as { CN : "China", US : "USA" }
+const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
+  acc[cur.key] = cur.display_name
+  return acc
+}, {})
+
+export default {
+  name: 'ComplexTable',
+  components: { Pagination },
+  directives: { waves },
+  filters: {
+    statusFilter(status) {
+      const statusMap = {
+        published: 'success',
+        draft: 'info',
+        deleted: 'danger'
+      }
+      return statusMap[status]
+    },
+    typeFilter(type) {
+      return calendarTypeKeyValue[type]
+    }
+  },
+  data() {
+    return {
+      tableKey: 0,
+      list: null,
+      total: 0,
+      listLoading: true,
+      listQuery: {
+        page: 1,
+        pageSize: 20,
+        adId: null
+      },
+      changeSort: {
+        id: null,
+        sort: null
+      },
+      sort: '',
+      importanceOptions: [1, 2, 3],
+      calendarTypeOptions,
+      sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
+      statusOptions: ['published', 'draft', 'deleted'],
+      showReviewer: false,
+      temp: {
+        id: undefined,
+        importance: 1,
+        remark: '',
+        timestamp: new Date(),
+        title: '',
+        type: '',
+        status: 'published'
+      },
+      dialogFormVisible: false,
+      dialogStatus: '',
+      textMap: {
+        update: 'Edit',
+        create: 'Create'
+      },
+      dialogPvVisible: false,
+      pvData: [],
+      rules: {
+        type: [{ required: true, message: 'type is required', trigger: 'change' }],
+        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
+        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
+      },
+      downloadLoading: false,
+      allArticle: [],
+      allLocation: {
+        LOCATION_NAME: null
+      }
+    }
+  },
+  created() {
+    this.getList()
+  },
+  methods: {
+    getList() {
+      this.listLoading = true
+      this.listQuery.adId = this.$route.params
+      fetchAdList(this.listQuery).then(response => {
+        this.list = response.data.list
+        this.total = response.data.totalCount
+        this.allArticle = response.data.allArticle
+        const ad_id = this.listQuery.adId.ID
+        this.allLocation = response.data.allLocation[ad_id]
+        // Just to simulate the time of the request
+        setTimeout(() => {
+          this.listLoading = false
+        }, 1.5 * 1000)
+      })
+    },
+    handleFilter() {
+      this.listQuery.page = 1
+      this.getList()
+    },
+    resetTemp() {
+      this.temp = {
+        id: undefined,
+        importance: 1,
+        remark: '',
+        timestamp: new Date(),
+        title: '',
+        status: 'published',
+        type: ''
+      }
+    },
+    handleView(row) {
+      this.$router.push(`/ad/list/${row.ID}`)
+    },
+    formatJson(filterVal) {
+      return this.list.map(v => filterVal.map(j => {
+        if (j === 'timestamp') {
+          return parseTime(v[j])
+        } else {
+          return v[j]
+        }
+      }))
+    },
+    getSortClass: function(key) {
+      const sort = this.listQuery.sort
+      return sort === `+${key}` ? 'ascending' : 'descending'
+    },
+    handleChangeSort(id, sort) {
+      this.changeSort.id = id
+      this.changeSort.sort = sort
+      fetchChangeSort(this.changeSort).then(response => {
+        setTimeout(() => {
+          this.listLoading = false
+        }, 1.5 * 1000)
+      })
+    },
+    getContent(aid) {
+      const titles = this.allArticle.filter(article => article.ID === aid).map(article => article.TITLE)
+      console.log(titles)
+      return titles.length > 0 ? titles[0] : aid
+    },
+    getHref(link) {
+      return link.indexOf('http') > -1 ? link : 'http://' + link
+    }
+  }
+}
+</script>

+ 1 - 1
vue.config.js

@@ -38,7 +38,7 @@ module.exports = {
     },
     proxy: {
       [process.env.VUE_APP_BASE_API]:{
-        target:"http://local.ng.backend.api.com",
+        target:"http://192.168.31.234:81",
         changeOrigin:true,
         pathRewrite:{
           ["^" + process.env.VUE_APP_BASE_API] : ""