index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="编号" prop="no">
  5. <el-input
  6. v-model="queryParams.no"
  7. placeholder="请输入编号"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. plain
  23. icon="el-icon-plus"
  24. size="mini"
  25. @click="handleAdd"
  26. v-hasPermi="['ad:html:add']"
  27. >新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button
  31. type="success"
  32. plain
  33. icon="el-icon-edit"
  34. size="mini"
  35. :disabled="single"
  36. @click="handleUpdate"
  37. v-hasPermi="['ad:html:edit']"
  38. >修改</el-button>
  39. </el-col>
  40. <el-col :span="1.5">
  41. <el-button
  42. type="danger"
  43. plain
  44. icon="el-icon-delete"
  45. size="mini"
  46. :disabled="multiple"
  47. @click="handleDelete"
  48. v-hasPermi="['ad:html:remove']"
  49. >删除</el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button
  53. type="warning"
  54. plain
  55. icon="el-icon-download"
  56. size="mini"
  57. :loading="exportLoading"
  58. @click="handleExport"
  59. v-hasPermi="['ad:html:export']"
  60. >导出</el-button>
  61. </el-col>
  62. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  63. </el-row>
  64. <el-table border v-loading="loading" :data="htmlList" @selection-change="handleSelectionChange">
  65. <el-table-column type="selection" width="55" align="center" />
  66. <el-table-column label="id" align="center" prop="id" />
  67. <el-table-column label="名称" align="center" prop="name" />
  68. <el-table-column label="描述" align="center" prop="remark" />
  69. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  70. <template slot-scope="scope">
  71. <el-button
  72. size="mini"
  73. type="text"
  74. icon="el-icon-edit"
  75. @click="handleUpdate(scope.row)"
  76. v-hasPermi="['ad:html:edit']"
  77. >修改</el-button>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. <pagination
  82. v-show="total>0"
  83. :total="total"
  84. :page.sync="queryParams.pageNum"
  85. :limit.sync="queryParams.pageSize"
  86. @pagination="getList"
  87. />
  88. <!-- 添加或修改广告信息流链接对话框 -->
  89. <el-dialog :title="title" :visible.sync="open" append-to-body>
  90. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  91. <el-form-item label="名称" prop="name">
  92. <el-input v-model="form.name" />
  93. </el-form-item>
  94. <el-form-item label="编辑页面">
  95. <el-button type="primary" @click="openH5(form.json)">
  96. 编辑页面
  97. </el-button>
  98. </el-form-item>
  99. <el-form-item label="描述" prop="remark">
  100. <el-input type="textarea" :row="5" v-model="form.remark" />
  101. </el-form-item>
  102. </el-form>
  103. <div slot="footer" class="dialog-footer">
  104. <el-button type="primary" @click="submitForm">确 定</el-button>
  105. <el-button @click="cancel">取 消</el-button>
  106. </div>
  107. </el-dialog>
  108. <!-- 添加或修改广告信息流链接对话框 -->
  109. <el-dialog title="编辑页面" :visible.sync="h5Open" append-to-body fullscreen>
  110. <H5Editor ref="h5Editor" />
  111. <div slot="footer" class="dialog-footer">
  112. <el-button type="primary" @click="h5Ok">确 定</el-button>
  113. <el-button @click="h5Cancel">取 消</el-button>
  114. </div>
  115. </el-dialog>
  116. <!-- 添加或修改广告信息流链接对话框 -->
  117. <el-dialog title="生成链接" :visible.sync="openUrl" width="600px" append-to-body>
  118. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  119. <el-form-item label="链接类型" prop="type">
  120. <el-radio v-model="urlForm.type" v-for="item in typeList" :key="item.type" :label="item.type" @change="accountChange">{{item.name}}</el-radio>
  121. </el-form-item>
  122. <el-form-item label="账号" prop="accountId">
  123. <el-select v-model="urlForm.accountId" filterable>
  124. <el-option v-for="item in accountList" :value="item.id" :key="item.id" :label="item.accountName" />
  125. </el-select>
  126. </el-form-item>
  127. <el-form-item label="链接" prop="type" v-if="this.urlForm.url">
  128. <a class="a" :href="this.urlForm.url" target="_blank">{{this.urlForm.url}}</a>
  129. <el-tooltip class="item" effect="dark" content="复制链接" placement="top">
  130. <i style="margin-left: 10px;cursor: pointer;color: #1890ff" class="el-icon-copy-document" @click="copyUrl"></i>
  131. </el-tooltip>
  132. </el-form-item>
  133. </el-form>
  134. <div slot="footer" class="dialog-footer">
  135. <el-button type="primary" @click="urlOk">生成</el-button>
  136. </div>
  137. </el-dialog>
  138. </div>
  139. </template>
  140. <script>
  141. import { listHtml, getHtml, delHtml, addHtml, updateHtml, exportHtml } from "@/api/ad/htmlTemplate";
  142. import { listAll as bdAccountListAll } from "@/api/baidu/BdAccount";
  143. import { listAll as youkuAccountListAll } from "@/api/ad/AdYouKuaccount.js";
  144. import { listAll as iqiyiAccountListAll } from "@/api/ad/AdIqiyiAccount.js";
  145. export default {
  146. name: "Html",
  147. data() {
  148. return {
  149. // 遮罩层
  150. loading: true,
  151. // 导出遮罩层
  152. exportLoading: false,
  153. // 选中数组
  154. ids: [],
  155. accountList: [],
  156. typeList: [{type: 0,name: "百度"}, {type: 1,name: "优酷"}, {type: 2,name: "爱奇艺"}],
  157. // 非单个禁用
  158. single: true,
  159. // 非多个禁用
  160. multiple: true,
  161. // 显示搜索条件
  162. showSearch: true,
  163. h5Open: false,
  164. // 总条数
  165. total: 0,
  166. // 广告信息流链接表格数据
  167. htmlList: [],
  168. // 弹出层标题
  169. title: "",
  170. // 是否显示弹出层
  171. open: false,
  172. openUrl: false,
  173. urlForm: {
  174. type: 0,
  175. accountId: null,
  176. url: null,
  177. },
  178. dataJSON: {},
  179. // 查询参数
  180. queryParams: {
  181. pageNum: 1,
  182. pageSize: 10,
  183. no: null,
  184. images: null,
  185. },
  186. // 表单参数
  187. form: {},
  188. // 表单校验
  189. rules: {
  190. }
  191. };
  192. },
  193. created() {
  194. this.getList();
  195. },
  196. methods: {
  197. openH5(){
  198. this.h5Open = true;
  199. this.$nextTick(() => {
  200. this.$refs.h5Editor.initData(this.form.json || "[]");
  201. });
  202. },
  203. h5Ok(){
  204. // 通过ref获取子组件的list数据
  205. const listData = this.$refs.h5Editor.list;
  206. this.form.json = JSON.stringify(listData);
  207. this.h5Open = false; // 关闭对话框
  208. },
  209. h5Cancel(){
  210. this.h5Open = false;
  211. },
  212. copyUrl(){
  213. navigator.clipboard.writeText(this.urlForm.url)
  214. .then(() => {
  215. this.msgSuccess("复制成功");
  216. })
  217. .catch(err => {
  218. this.msgError("复制失败");
  219. });
  220. },
  221. urlOk(){
  222. if(!this.form.url){
  223. this.msgError("推广页面信息错误,请联系管理员!");
  224. return;
  225. }
  226. if(this.urlForm.type == null || this.urlForm.type == undefined){
  227. this.msgError("链接类型不能为空");
  228. return;
  229. }
  230. if(!this.urlForm.accountId){
  231. this.msgError("账号ID不能为空");
  232. return;
  233. }
  234. this.urlForm.url = this.form.url + "&type=" + this.urlForm.type + "&accountId=" + this.urlForm.accountId;
  235. },
  236. accountChange(){
  237. let type = this.urlForm.type;
  238. this.urlForm.accountId = undefined;
  239. this.urlForm.url = undefined;
  240. if(type == 0){
  241. bdAccountListAll({}).then(res => {
  242. this.accountList = res.data;
  243. })
  244. }
  245. if(type == 1){
  246. youkuAccountListAll().then(res => {
  247. this.accountList = res.data;
  248. })
  249. }
  250. if(type == 2){
  251. iqiyiAccountListAll().then(res => {
  252. this.accountList = res.data;
  253. })
  254. }
  255. },
  256. openUrlFun(row){
  257. getHtml(row.id).then(response => {
  258. this.form = response.data;
  259. if(this.form.dataJson){
  260. this.dataJSON = JSON.parse(this.form.dataJson)
  261. }
  262. this.urlForm = {
  263. type: 0,
  264. accountId: null,
  265. url: null,
  266. };
  267. this.accountChange();
  268. this.openUrl = true;
  269. });
  270. },
  271. /** 查询广告信息流链接列表 */
  272. getList() {
  273. this.loading = true;
  274. listHtml(this.queryParams).then(response => {
  275. this.htmlList = response.rows;
  276. this.total = response.total;
  277. this.loading = false;
  278. });
  279. },
  280. // 取消按钮
  281. cancel() {
  282. this.open = false;
  283. this.reset();
  284. },
  285. // 表单重置
  286. reset() {
  287. this.dataJSON = {};
  288. this.form = {
  289. id: null,
  290. no: null,
  291. images: null,
  292. createTime: null,
  293. createBy: null,
  294. updateBy: null,
  295. dataJSON: "",
  296. updateTime: null
  297. };
  298. this.resetForm("form");
  299. },
  300. /** 搜索按钮操作 */
  301. handleQuery() {
  302. this.queryParams.pageNum = 1;
  303. this.getList();
  304. },
  305. /** 重置按钮操作 */
  306. resetQuery() {
  307. this.resetForm("queryForm");
  308. this.handleQuery();
  309. },
  310. // 多选框选中数据
  311. handleSelectionChange(selection) {
  312. this.ids = selection.map(item => item.id)
  313. this.single = selection.length!==1
  314. this.multiple = !selection.length
  315. },
  316. /** 新增按钮操作 */
  317. handleAdd() {
  318. this.reset();
  319. this.open = true;
  320. this.title = "添加广告信息流链接";
  321. },
  322. /** 修改按钮操作 */
  323. handleUpdate(row) {
  324. this.reset();
  325. const id = row.id || this.ids
  326. getHtml(id).then(response => {
  327. this.form = response.data;
  328. if(this.form.dataJson){
  329. this.dataJSON = JSON.parse(this.form.dataJson)
  330. }
  331. this.open = true;
  332. this.title = "修改广告信息流链接";
  333. });
  334. },
  335. /** 提交按钮 */
  336. submitForm() {
  337. this.$refs["form"].validate(valid => {
  338. if (valid) {
  339. if(this.dataJSON){
  340. this.form.dataJson = JSON.stringify(this.dataJSON);
  341. }
  342. if (this.form.id != null) {
  343. updateHtml(this.form).then(response => {
  344. this.msgSuccess("修改成功");
  345. this.open = false;
  346. this.getList();
  347. });
  348. } else {
  349. addHtml(this.form).then(response => {
  350. this.msgSuccess("新增成功");
  351. this.open = false;
  352. this.getList();
  353. });
  354. }
  355. }
  356. });
  357. },
  358. /** 删除按钮操作 */
  359. handleDelete(row) {
  360. const ids = row.id || this.ids;
  361. this.$confirm('是否确认删除广告信息流链接编号为"' + ids + '"的数据项?', "警告", {
  362. confirmButtonText: "确定",
  363. cancelButtonText: "取消",
  364. type: "warning"
  365. }).then(function() {
  366. return delHtml(ids);
  367. }).then(() => {
  368. this.getList();
  369. this.msgSuccess("删除成功");
  370. }).catch(() => {});
  371. },
  372. /** 导出按钮操作 */
  373. handleExport() {
  374. const queryParams = this.queryParams;
  375. this.$confirm('是否确认导出所有广告信息流链接数据项?', "警告", {
  376. confirmButtonText: "确定",
  377. cancelButtonText: "取消",
  378. type: "warning"
  379. }).then(() => {
  380. this.exportLoading = true;
  381. return exportHtml(queryParams);
  382. }).then(response => {
  383. this.download(response.msg);
  384. this.exportLoading = false;
  385. }).catch(() => {});
  386. }
  387. }
  388. };
  389. </script>
  390. <style>
  391. .a{
  392. text-decoration: underline;
  393. }
  394. .a:hover{
  395. text-decoration: underline;
  396. }
  397. </style>