• TienChin 渠道管理-前端展示渠道信息


    在编写 Vue 项目的时候我们可以使用 IDEA 当中提供的一个工具叫做 structure,也就是说可以很轻松的列举出当前 Vue 文件的大致结构,点那个就会跳转到对应的地方。

    image-20230830233509289

    简简单单介绍一个编写Vue时的一个小技巧,那么接下来进入核心内容,展示渠道信息的开发。

    在 api 文件夹模块当中新建一个 tienchin 的文件夹,在当中编写一个 channel.js:

    image-20230917130825100

    channel.js:

    1. import request from '@/utils/request'
    2. /**
    3. * 查询渠道列表
    4. * @param query 查询条件参数
    5. * @returns {*} 查询结果
    6. */
    7. export function listChannel(query) {
    8. return request({
    9. url: '/tienchin/channel/list',
    10. method: 'get',
    11. params: query
    12. })
    13. }
    14. // 查询渠道详细
    15. export function getInfo(channelId) {
    16. return request({
    17. url: '/tienchin/channel/' + channelId,
    18. method: 'get'
    19. })
    20. }
    21. // 新增渠道
    22. export function addChannel(data) {
    23. return request({
    24. url: '/tienchin/channel',
    25. method: 'post',
    26. data: data
    27. })
    28. }
    29. // 修改渠道
    30. export function updateChannel(data) {
    31. return request({
    32. url: '/tienchin/channel',
    33. method: 'put',
    34. data: data
    35. })
    36. }
    37. // 删除渠道
    38. export function delChannel(channelIds) {
    39. return request({
    40. url: '/tienchin/channel/' + channelIds,
    41. method: 'delete'
    42. })
    43. }

    主要的就是编写了一下对接后台的 api。

    接下来就是页面的调用代码:

    image-20230917131034500

    index.vue:

    1. <script setup name="Channel">
    2. import {getToken} from "@/utils/auth";
    3. import {listChannel, addChannel, getInfo, updateChannel, delChannel} from "@/api/tienchin/channel";
    4. const {proxy} = getCurrentInstance();
    5. const {
    6. channel_type,
    7. channel_status
    8. } = proxy.useDict("channel_type", "channel_status");
    9. const channelList = ref([]);
    10. const open = ref(false);
    11. const loading = ref(true);
    12. const showSearch = ref(true);
    13. const ids = ref([]);
    14. const single = ref(true);
    15. const multiple = ref(true);
    16. const total = ref(0);
    17. const title = ref("");
    18. const dateRange = ref([]);
    19. const data = reactive({
    20. form: {},
    21. queryParams: {
    22. pageNum: 1,
    23. pageSize: 10,
    24. channelName: undefined,
    25. type: undefined,
    26. status: undefined
    27. },
    28. rules: {
    29. channelName: [{required: true, message: "渠道名称不能为空", trigger: "blur"}],
    30. status: [{required: true, message: "渠道状态不能为空", trigger: "blur"}],
    31. type: [{required: true, message: "渠道类型不能为空", trigger: "blur"}]
    32. },
    33. });
    34. /*** 渠道导入参数 */
    35. const upload = reactive({
    36. // 是否显示弹出层(渠道导入)
    37. open: false,
    38. // 弹出层标题(渠道导入)
    39. title: "",
    40. // 是否禁用上传
    41. isUploading: false,
    42. // 是否更新已经存在的渠道数据
    43. updateSupport: 0,
    44. // 设置上传的请求头部
    45. headers: {Authorization: "Bearer " + getToken()},
    46. // 上传的地址
    47. url: import.meta.env.VITE_APP_BASE_API + "tienchin/channel/importData"
    48. });
    49. const {queryParams, form, rules} = toRefs(data);
    50. /**
    51. * 查询渠道列表
    52. */
    53. function getList() {
    54. loading.value = true;
    55. listChannel(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
    56. channelList.value = response.rows;
    57. total.value = response.total;
    58. loading.value = false;
    59. });
    60. }
    61. /** 搜索按钮操作 */
    62. function handleQuery() {
    63. queryParams.value.pageNum = 1;
    64. getList();
    65. }
    66. /** 重置按钮操作 */
    67. function resetQuery() {
    68. dateRange.value = [];
    69. proxy.resetForm("queryRef");
    70. handleQuery();
    71. }
    72. /** 删除按钮操作 */
    73. function handleDelete(row) {
    74. const channelIds = row.channelId || ids.value;
    75. proxy.$modal.confirm('是否确认删除渠道编号为"' + channelIds + '"的数据项?').then(function () {
    76. return delChannel(channelIds);
    77. }).then(() => {
    78. getList();
    79. proxy.$modal.msgSuccess("删除成功");
    80. }).catch(() => {
    81. });
    82. }
    83. /**
    84. * 导入按钮操作
    85. **/
    86. function handleImport() {
    87. upload.title = "渠道导入";
    88. upload.open = true;
    89. };
    90. /**文件上传中处理 */
    91. const handleFileUploadProgress = (event, file, fileList) => {
    92. upload.isUploading = true;
    93. };
    94. /** 文件上传成功处理 */
    95. const handleFileSuccess = (response, file, fileList) => {
    96. upload.open = false;
    97. upload.isUploading = false;
    98. proxy.$refs["uploadRef"].clearFiles();
    99. proxy.$alert("
      " + response.msg + "
      "
      , "导入结果", {dangerouslyUseHTMLString: true});
    100. getList();
    101. };
    102. /** 提交上传文件 */
    103. function submitFileForm() {
    104. proxy.$refs["uploadRef"].submit();
    105. };
    106. /** 下载模板操作 */
    107. function importTemplate() {
    108. proxy.download("tienchin/channel/importTemplate", {}, `channel_template_${new Date().getTime()}.xlsx`);
    109. };
    110. /** 导出按钮操作 */
    111. function handleExport() {
    112. proxy.download("tienchin/channel/export", {
    113. ...queryParams.value,
    114. }, `channel_${new Date().getTime()}.xlsx`);
    115. }
    116. /**
    117. * 多选框选中数据
    118. * 点击表格中的第一列的多选框,会触发这个方法
    119. * @param selection 选中的数据
    120. */
    121. function handleSelectionChange(selection) {
    122. ids.value = selection.map(item => item.channelId);
    123. single.value = selection.length != 1;
    124. multiple.value = !selection.length;
    125. }
    126. /** 重置新增的表单以及其他数据 */
    127. function reset() {
    128. form.value = {
    129. // 渠道名称
    130. channelName: undefined,
    131. status: undefined,
    132. type: undefined,
    133. // 备注
    134. remark: undefined
    135. };
    136. proxy.resetForm("channelRef");
    137. }
    138. /** 添加渠道 */
    139. function handleAdd() {
    140. reset();
    141. // 打开对话框
    142. open.value = true;
    143. // 对话框的标题
    144. title.value = "添加渠道";
    145. }
    146. /**
    147. * 修改渠道
    148. * 无论是点击最上面的修改按钮,还是点击表格中的修改按钮,都会调用这个方法
    149. * 不同的是,如果是点击表格中的修改按钮,会把当前行的数据传递过来
    150. * @param row 行数据
    151. * @returns {Promise}
    152. */
    153. function handleUpdate(row) {
    154. reset();
    155. // 这个渠道ID有两种来源:如果是点击表格中的修改按钮,则通过row.channelId获取
    156. // 如果是点击最上面的修改按钮,则通过ids.value获取
    157. const channelId = row.channelId || ids.value;
    158. getInfo(channelId).then(response => {
    159. form.value = response.data;
    160. open.value = true;
    161. title.value = "修改渠道";
    162. });
    163. }
    164. /** 提交按钮 */
    165. function submitForm() {
    166. proxy.$refs["channelRef"].validate(valid => {
    167. if (valid) {
    168. if (form.value.channelId != undefined) {
    169. updateChannel(form.value).then(response => {
    170. // 删除掉 form 中不需要提交的数据
    171. delete form.value.updateTime;
    172. delete form.value.createTime;
    173. proxy.$modal.msgSuccess("修改成功");
    174. open.value = false;
    175. getList();
    176. });
    177. } else {
    178. addChannel(form.value).then(response => {
    179. proxy.$modal.msgSuccess("新增成功");
    180. open.value = false;
    181. getList();
    182. });
    183. }
    184. }
    185. });
    186. }
    187. /** 取消按钮 */
    188. function cancel() {
    189. open.value = false;
    190. reset();
    191. }
    192. getList();
    193. script>

    !> 声明:本人在开发这个模块当中没有记录开发过程,我这里只是简简单单写一个文章来做个备份给新人看这个项目有个好的铺垫。

  • 相关阅读:
    C Primer Plus(6) 中文版 第12章 存储类别、链接和内存管理 12.3 掷骰子
    SAP MM学习笔记 - 错误 ME092 - Material mainly procured internally(原则上该物料只能内部调达)
    渐变圆角边框css
    go | defer、panic、recover
    OrcaTerm AI
    【python学习第11节:numpy】
    第三章变量
    如何用大模型RAG做医疗问答系统
    yolov7 onnx tensorrt 批量预测 全网首发
    【数学建模】——力学模型建立的基本理论及方法
  • 原文地址:https://blog.csdn.net/XiaohuihuiHuiYi/article/details/132999978