homeLink.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div>
  3. <el-row class="handle-box" style="margin-bottom: 10px">
  4. <el-col :span="20">
  5. <el-input v-model="linkName" class="ch-input ch-input-size" placeholder="链接名称" size="small" @keyup.enter.native="handleSearch()" />
  6. <el-button class="ch-button" size="small" @click="handleSearch()"><i class="el-icon-search" />&nbsp;搜索</el-button>
  7. <el-button class="ch-button-warning" size="small" @click="handleReset()"><i class="el-icon-search" />&nbsp;重置</el-button>
  8. </el-col>
  9. <el-col :span="4">
  10. <el-button class="ch-button" size="small" style="float: right" @click="handleAdd()"><i class="el-icon-menu" />&nbsp;新增</el-button>
  11. </el-col>
  12. </el-row>
  13. <el-row class="handle-box">
  14. <el-col :span="24">
  15. <el-table v-loading="loading" :data="AllData" row-class-name="g_table_row" stripe>
  16. <el-table-column type="index" width="60" />
  17. <el-table-column align="center" header-align="center" label="简图" width="200">
  18. <template scope="scope">
  19. <img :src="$constant.BASE_URI + '/FileController/viewImg/'+scope.row.linkImage" style="height: 50px;margin-top: 4px">
  20. </template>
  21. </el-table-column>
  22. <el-table-column align="center" header-align="center" label="下载" width="200">
  23. <template scope="scope">
  24. <a :href="$constant.BASE_URI + '/FileController/download/'+scope.row.linkImage">{{ scope.row.linkName }}</a>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="链接名" prop="linkName" />
  28. <el-table-column label="链接地址" prop="linkUrl" />
  29. <el-table-column label="排序号" prop="linkOrder" />
  30. <el-table-column header-align="center" label="操作" width="180">
  31. <template scope="scope">
  32. <el-button size="mini" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
  33. <el-button size="mini" type="info" @click="handleDel(scope.row)">删除</el-button>
  34. </template>
  35. </el-table-column>
  36. </el-table>
  37. <div class="table-page">
  38. <el-pagination
  39. :current-page.sync="currentPage"
  40. :page-size="pageSize"
  41. :total="allpage"
  42. background
  43. layout="total, prev, pager, next"
  44. @current-change="handleCurrentChange"
  45. />
  46. </div>
  47. </el-col>
  48. </el-row>
  49. <el-dialog :title="dialogTitle" class="statistic_base" :visible.sync="dialogVisible" top="50px" width="75%" @open="dlgOpen" append-to-body>
  50. <el-form ref="form" :model="form" :rules="rules" style="width: 100%;padding: 5px">
  51. <el-row>
  52. <el-col style="padding-bottom: 10px">
  53. <span class="card_title">基本信息</span>
  54. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  55. <el-row>
  56. <el-col :span="6">
  57. <div class="info-label">
  58. <p class="logo-title">链接图</p>
  59. <p style="font-size: 12px;font-family: STFangsong;margin-bottom: 5px">Click Image To Change</p>
  60. </div>
  61. <el-form-item>
  62. <el-upload
  63. :http-request="uploadLinkImage"
  64. :on-success="logoHandleSuccess"
  65. :show-file-list="false"
  66. action="http://localhost:9002/FileController/upload"
  67. class="avatar-uploader"
  68. method="post"
  69. >
  70. <img v-if="form.linkImage" :src="$constant.BASE_URI + '/FileController/viewImg/'+form.linkImage" class="avatar">
  71. <i v-else class="el-icon-plus avatar-uploader-icon" />
  72. </el-upload>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="18">
  76. <el-row>
  77. <el-col :span="22" class="col-txt">&nbsp;</el-col>
  78. </el-row>
  79. <el-row>
  80. <el-col :span="5" class="col-txt"><span>链接名</span></el-col>
  81. <el-col :span="17" class="col-input">
  82. <el-form-item>
  83. <el-input v-model="form.linkName" />
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. <el-row>
  88. <el-col :span="5" class="col-txt"><span>链接地址</span></el-col>
  89. <el-col :span="17" class="col-input">
  90. <el-form-item prop="linkUrl">
  91. <el-input v-model="form.linkUrl" />
  92. </el-form-item>
  93. </el-col>
  94. </el-row>
  95. <el-row>
  96. <el-col :span="5" class="col-txt"><span>排序号</span></el-col>
  97. <el-col :span="17" class="col-input">
  98. <el-form-item>
  99. <el-input v-model="form.linkOrder" />
  100. </el-form-item>
  101. </el-col>
  102. </el-row>
  103. </el-col>
  104. </el-row>
  105. </el-card>
  106. </el-col>
  107. </el-row>
  108. </el-form>
  109. <div slot="footer">
  110. <el-button @click="dialogVisible = false">取 消</el-button>
  111. <el-button type="primary" @click="confirmSubmit()">确 定</el-button>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import Base from '../base/base'
  118. import BaseData from '../base/baseData'
  119. import { upload } from '../../static/utils/channel'
  120. import { validateURL } from '../../static/utils/validate'
  121. export default {
  122. name: 'HomeLink',
  123. mixins: [Base, BaseData],
  124. data() {
  125. const validateURI = (rule, value, callback) => {
  126. if (validateURL(value)) {
  127. callback()
  128. } else {
  129. callback(new Error('请输入正确的域名或IP地址,需包含‘http://’或‘https://’'))
  130. }
  131. }
  132. return {
  133. // 列表相关
  134. linkName: '',
  135. AllData: [],
  136. loading: false,
  137. // 弹框相关
  138. dialogVisible: false,
  139. dialogTitle: '新增',
  140. isAdd: true,
  141. form: {
  142. id: '',
  143. linkImage: '',
  144. linkUrl: '',
  145. linkName: '',
  146. linkOrder: ''
  147. },
  148. rules: {
  149. linkUrl: [{ required: true, trigger: 'blur', validator: validateURI }]
  150. }
  151. }
  152. },
  153. mounted() {
  154. this.getData()
  155. },
  156. methods: {
  157. getData: function() {
  158. const _this = this
  159. _this.loading = true
  160. _this.AllData = []
  161. const postData = this.getPostData()
  162. this.baseRequest('list', postData).then((res) => {
  163. if (res.data.rows) {
  164. res.data.rows.forEach(function(item) {
  165. const json = _this.getItemJson(item)
  166. _this.AllData.push(json)
  167. })
  168. _this.allpage = res.data.total
  169. }
  170. _this.loading = false
  171. }).catch(() => {
  172. })
  173. },
  174. handleSearch: function() {
  175. this.getData()
  176. },
  177. handleReset: function() {
  178. this.linkName = ''
  179. },
  180. getPostData: function() {
  181. return {
  182. linkName: this.linkName,
  183. pageNum: this.currentPage,
  184. pageSize: this.pageSize
  185. }
  186. },
  187. getItemJson: function(item) {
  188. const json = {
  189. linkImage: item.linkImage,
  190. linkUrl: item.linkUrl,
  191. linkName: item.linkName,
  192. linkOrder: item.linkOrder,
  193. id: item.id
  194. }
  195. return json
  196. },
  197. dlgOpen: function() {
  198. const _this = this
  199. if (_this.form.id !== '') {
  200. const postData = {
  201. id: _this.form.id
  202. }
  203. this.baseRequest('getById', postData).then((res) => {
  204. if (res.data) {
  205. _this.form.linkImage = res.data.linkImage
  206. _this.form.linkUrl = res.data.linkUrl
  207. _this.form.linkName = res.data.linkName
  208. _this.form.linkOrder = res.data.linkOrder
  209. _this.form.id = res.data.id
  210. }
  211. }).catch(() => {
  212. })
  213. }
  214. },
  215. /* 编辑*/
  216. handleEdit: function(val) {
  217. this.isAdd = false
  218. this.form.id = val.id
  219. this.dialogVisible = true
  220. this.dialogTitle = '编辑'
  221. },
  222. /* 新增*/
  223. handleAdd: function() {
  224. this.form = {
  225. id: '',
  226. linkImage: '',
  227. linkUrl: '',
  228. linkName: '',
  229. linkOrder: ''
  230. }
  231. this.isAdd = true
  232. this.dialogVisible = true
  233. this.dialogTitle = '新增'
  234. },
  235. confirmSubmit: function() {
  236. const _this = this
  237. this.$refs.form.validate(valid => {
  238. if (valid) {
  239. let soaUrl = 'edit'
  240. const postData = {
  241. linkImage: _this.form.linkImage,
  242. linkUrl: _this.form.linkUrl,
  243. linkName: _this.form.linkName,
  244. linkOrder: _this.form.linkOrder,
  245. id: _this.form.id
  246. }
  247. if (this.isAdd) {
  248. soaUrl = 'add'
  249. }
  250. this.opRecord(postData, soaUrl)
  251. } else {
  252. //console.log('error submit!!')
  253. return false
  254. }
  255. })
  256. },
  257. uploadLinkImage: function(param) {
  258. upload(param, true, true).then((res) => {
  259. this.form.linkImage = res
  260. })
  261. },
  262. baseRequest: function(opUrl, postData) {
  263. return this.$channel.globeRequest('SysHomeLinkController', opUrl, postData, 'project')
  264. }
  265. }
  266. }
  267. </script>
  268. <style scoped>
  269. .ch-input .el-input__inner {
  270. border-radius: 0px;
  271. border-color: #32323A;
  272. }
  273. .ch-input-size {
  274. width: 150px;
  275. }
  276. .ch-button {
  277. border-radius: 0px;
  278. border-color: #32323A;
  279. background-color: #32323A;
  280. color: #fff;
  281. }
  282. .ch-button-warning {
  283. margin-left: 10px;
  284. border-radius: 0px;
  285. border-color: #E6A23C;
  286. background-color: #E6A23C;
  287. color: #fff;
  288. }
  289. </style>
  290. <style>
  291. .el-table th, .el-table td {
  292. padding: 5px 0px;
  293. }
  294. .avatar-uploader {
  295. text-align: center;
  296. }
  297. .avatar-uploader .el-upload {
  298. border: 2px dashed #d9d9d9;
  299. padding: 2px;
  300. border-radius: 3px;
  301. cursor: pointer;
  302. position: relative;
  303. overflow: hidden;
  304. width: 128px;
  305. height: 128px;
  306. }
  307. .avatar-uploader-icon {
  308. font-size: 28px;
  309. color: #8c939d;
  310. line-height: 128px;
  311. text-align: center;
  312. }
  313. .avatar-uploader .el-upload:hover {
  314. border-color: #94b131;
  315. }
  316. .avatar {
  317. position: absolute;
  318. margin: auto;
  319. top: 0px;
  320. right: 0px;
  321. bottom: 0px;
  322. left: 0px;
  323. max-width:100%;
  324. max-height:100%
  325. }
  326. .info-label{
  327. text-align: center;
  328. }
  329. .logo-title {
  330. text-align: center;
  331. font-weight: bold;
  332. font-size: 18px;
  333. padding-bottom: 5px;
  334. }
  335. </style>