vue3-sfc-loader 加载长途.vue文件(sfc)案例

打印 上一主题 下一主题

主题 1025|帖子 1025|积分 3075

注意事项

   

  • style标签假如增加了lang比如:lang=“scss”,需要提供scss-loader的处置惩罚器,这个暂时没研究,我的处置惩罚方式是将动态模版的css放在了全局
  • 打包暂时还没有测试,后面测试了会同步更新
  安装vue3-sfc-loader

  1. npm install vue3-sfc-loader
复制代码
后端vue模版 (sfc案例)

   后端我用的是java加Velocity模版引擎(.vm模版)
  vm模版引擎位置:

vm模版

  1. <template>
  2.   <view class="cus-tab theme theme-page">
  3.     <uniForms ref="formRef" :modelValue="formData" validate-trigger="bind">
  4.       <table class="tableCla">
  5.         <colgroup>
  6.           <col style="width: 20px;">
  7.           <col style="width: 70px;">
  8.           <col style="width: 130px;">
  9.           <!-- <col style="width: 70px;"> -->
  10.         </colgroup>
  11.         <thead>
  12.         <tr>
  13.           <th class="slash-wrap" colspan="2">
  14.             <div class="oline">
  15.               <span class="span1">年级</span>
  16.               <span class="span2">姓名</span>
  17.             </div>
  18.           </th>
  19.           <th>高三二班</th>
  20.           <th>异议数据</th>
  21.         </tr>
  22.         </thead>
  23.         <tbody>
  24.         <tr>
  25.           <td colspan="2">身高</td>
  26.           <td>身高</td>
  27.           <td>
  28.             <uniFormsItem name="sga">
  29.               <view class="input-cla theme-flex">
  30.                 <uniEasyinput :clearable="false" v-model="formData.sga"
  31.                                placeholder=""></uniEasyinput>
  32.                 <text>cm</text>
  33.               </view>
  34.             </uniFormsItem>
  35.           </td>
  36.         </tr>
  37.         <tr>
  38.           <td colspan="2">体重</td>
  39.           <td>88888888</td>
  40.           <td>
  41.             <uniFormsItem name="tz">
  42.               <view class="input-cla theme-flex">
  43.                 <uniEasyinput :clearable="false" v-model="formData.tz"
  44.                                placeholder=""></uniEasyinput>
  45.                 <text>kg</text>
  46.               </view>
  47.             </uniFormsItem>
  48.           </td>
  49.         </tr>
  50.         <tr>
  51.           <td colspan="1" rowspan="3">眼科检查</td>
  52.           <td>裸眼视力</td>
  53.           <td>das</td>
  54.           <td>
  55.             <view class="theme-flex">
  56.               <view class="input-cla theme-flex">
  57.                 <uniFormsItem name="lyz">
  58.                   <view class="input-cla theme-flex">
  59.                     <text>左</text>
  60.                     <uniEasyinput :clearable="false" v-model="formData.lyz"
  61.                                    placeholder=""></uniEasyinput>
  62.                   </view>
  63.                 </uniFormsItem>
  64.                 <text>/</text>
  65.                 <uniFormsItem name="lyy">
  66.                   <view class="input-cla theme-flex">
  67.                     <text>右</text>
  68.                     <uniEasyinput :clearable="false" v-model="formData.lyy"
  69.                                    placeholder=""></uniEasyinput>
  70.                   </view>
  71.                 </uniFormsItem>
  72.               </view>
  73.             </view>
  74.           </td>
  75.         </tr>
  76.         <tr>
  77.           <td>矫正视力</td>
  78.           <td>John</td>
  79.           <td>
  80.             <view class="theme-flex">
  81.               <view class="input-cla theme-flex">
  82.                 <uniFormsItem name="jzz">
  83.                   <view class="input-cla theme-flex">
  84.                     <text>左</text>
  85.                     <uniEasyinput :clearable="false" v-model="formData.jzz"
  86.                                    placeholder=""></uniEasyinput>
  87.                   </view>
  88.                 </uniFormsItem>
  89.                 <text>/</text>
  90.                 <uniFormsItem name="jzy">
  91.                   <view class="input-cla theme-flex">
  92.                     <text>右</text>
  93.                     <uniEasyinput :clearable="false" v-model="formData.jzy"
  94.                                    placeholder=""></uniEasyinput>
  95.                   </view>
  96.                 </uniFormsItem>
  97.               </view>
  98.             </view>
  99.           </td>
  100.         </tr>
  101.         <tr>
  102.           <td>角膜炎</td>
  103.           <td>John</td>
  104.           <td>
  105.             <view class="input-cla theme-flex">
  106.               <wdCheckbox v-model="formData.jmy" shape="square">有异议</wdCheckbox>
  107.             </view>
  108.           </td>
  109.         </tr>
  110.         <tr>
  111.           <td colspan="1" rowspan="4">内科检查</td>
  112.           <td>心脏</td>
  113.           <td>John</td>
  114.           <td>
  115.             <view class="input-cla theme-flex">
  116.               <wdCheckbox v-model="formData.xz" shape="square">有异议</wdCheckbox>
  117.             </view>
  118.           </td>
  119.         </tr>
  120.         <tr>
  121.           <td>肺</td>
  122.           <td>John</td>
  123.           <td>
  124.             <view class="input-cla theme-flex">
  125.               <wdCheckbox v-model="formData.fei" shape="square">有异议</wdCheckbox>
  126.             </view>
  127.           </td>
  128.         </tr>
  129.         <tr>
  130.           <td>肝</td>
  131.           <td>John</td>
  132.           <td>
  133.             <view class="input-cla theme-flex">
  134.               <wdCheckbox v-model="formData.gan" shape="square">有异议</wdCheckbox>
  135.             </view>
  136.           </td>
  137.         </tr>
  138.         <tr>
  139.           <td>脾</td>
  140.           <td>John</td>
  141.           <td>
  142.             <view class="input-cla theme-flex">
  143.               <wdCheckbox v-model="formData.pi" shape="square">有异议</wdCheckbox>
  144.             </view>
  145.           </td>
  146.         </tr>
  147.         <tr>
  148.           <td colspan="1" rowspan="8">外科检查</td>
  149.           <td>头部</td>
  150.           <td>John</td>
  151.           <td>
  152.             <view class="input-cla theme-flex">
  153.               <wdCheckbox v-model="formData.tb" shape="square">有异议</wdCheckbox>
  154.             </view>
  155.           </td>
  156.         </tr>
  157.         <tr>
  158.           <td>颈部</td>
  159.           <td>John</td>
  160.           <td>
  161.             <view class="input-cla theme-flex">
  162.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  163.             </view>
  164.           </td>
  165.         </tr>
  166.         <tr>
  167.           <td>甲状腺</td>
  168.           <td>John</td>
  169.           <td>
  170.             <view class="input-cla theme-flex">
  171.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  172.             </view>
  173.           </td>
  174.         </tr>
  175.         <tr>
  176.           <td>胸部</td>
  177.           <td>John</td>
  178.           <td>
  179.             <view class="input-cla theme-flex">
  180.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  181.             </view>
  182.           </td>
  183.         </tr>
  184.         <tr>
  185.           <td>脊椎</td>
  186.           <td>John</td>
  187.           <td>
  188.             <view class="input-cla theme-flex">
  189.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  190.             </view>
  191.           </td>
  192.         </tr>
  193.         <tr>
  194.           <td>四肢</td>
  195.           <td>John</td>
  196.           <td>
  197.             <view class="input-cla theme-flex">
  198.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  199.             </view>
  200.           </td>
  201.         </tr>
  202.         <tr>
  203.           <td>皮肤</td>
  204.           <td>John</td>
  205.           <td>
  206.             <view class="input-cla theme-flex">
  207.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  208.             </view>
  209.           </td>
  210.         </tr>
  211.         <tr>
  212.           <td>淋巴结</td>
  213.           <td>John</td>
  214.           <td>
  215.             <view class="input-cla theme-flex">
  216.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  217.             </view>
  218.           </td>
  219.         </tr>
  220.         <tr>
  221.           <td colspan="1" rowspan="3">耳鼻喉科</td>
  222.           <td>耳</td>
  223.           <td>John</td>
  224.           <td>
  225.             <view class="input-cla theme-flex">
  226.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  227.             </view>
  228.           </td>
  229.         </tr>
  230.         <tr>
  231.           <td>鼻</td>
  232.           <td>John</td>
  233.           <td>
  234.             <view class="input-cla theme-flex">
  235.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  236.             </view>
  237.           </td>
  238.         </tr>
  239.         <tr>
  240.           <td>扁桃体</td>
  241.           <td>John</td>
  242.           <td>
  243.             <view class="input-cla theme-flex">
  244.               <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
  245.             </view>
  246.           </td>
  247.         </tr>
  248.         <tr>
  249.           <td colspan="4">
  250.             <view class="input-text-cla">
  251.               <uniFormsItem required name="fkyj" :rules="[{required: true,errorMessage: '请填写反馈意见',}]">
  252.                 <view class="theme-flex">
  253.                   <uniEasyinput type="textarea" autoHeight :clearable="false" v-model="formData.fkyj"
  254.                                  placeholder="请输入反馈意见"></uniEasyinput>
  255.                 </view>
  256.               </uniFormsItem>
  257.             </view>
  258.           </td>
  259.         </tr>
  260.         </tbody>
  261.       </table>
  262.       <view>
  263.         <view class="tips-clas theme-flex">
  264.           <text>1. 请如实填写,填写完成后保存</text>
  265.           <text>2. 异议数据需机构审核,请耐心等待</text>
  266.         </view>
  267.         <view class="bot-box">
  268.           <wdButton @click="submit">提交审核</wdButton>
  269.         </view>
  270.       </view>
  271.     </uniForms>
  272.   </view>
  273. </template>
  274. <script setup name="Abnormal">
  275.   import { ref, reactive } from 'vue'
  276.   import uniForms from 'uniForms'
  277.   import uniFormsItem from 'uniFormsItem'
  278.   import uniEasyinput from 'uniEasyinput'
  279.   import wdCheckbox from 'wdCheckbox'
  280.   import wdButton from 'wdButton'
  281.   const formRef = ref();
  282.   const formData = reactive({
  283.     sga: '',
  284.     sg: '',
  285.     tz: '',
  286.     lyz: '',
  287.     lyy: '',
  288.     jzz: '',
  289.     jzy: '',
  290.     fkyj: '',
  291.     jmy: false,
  292.     xz: false,
  293.     fei: false,
  294.     gan: false,
  295.     pi: false,
  296.     tb: false,
  297.   });
  298.   const submit = () => {
  299.     formRef.value.validate().then((res) => {
  300.       console.log('表单数据信息:', res);
  301.     }).catch((err) => {
  302.       console.log('表单错误信息:', err);
  303.     })
  304.   };
  305. </script>
  306. <style lang="scss">
  307.   .oline {
  308.     border-top: 50px #c5c5c5 solid;
  309.     width: 0px;
  310.     height: 0px;
  311.     border-left: 90px #ffffff solid;
  312.     position: relative;
  313.   }
  314.   .oline::before {
  315.     position: absolute;
  316.     top: -40px;
  317.     left: -80px;
  318.     width: 80px;
  319.     height: 40px;
  320.     /* background: #fff url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=) no-repeat 100% center; */
  321.     content: '';
  322.   }
  323.   .span1 {
  324.     font-style: normal;
  325.     display: block;
  326.     position: absolute;
  327.     top: -40px;
  328.     left: -40px;
  329.     width: 35px;
  330.   }
  331.   .span2 {
  332.     font-style: normal;
  333.     display: block;
  334.     position: absolute;
  335.     top: -25px;
  336.     left: -70px;
  337.     width: 55px;
  338.   }
  339.   .top {
  340.     padding: 10px;
  341.     border-bottom: 1px solid #e8e8e8;
  342.   }
  343.   .aColor>a {
  344.     color: rgba(0, 0, 0, 0.65);
  345.   }
  346.   .tableCla {
  347.     width: 100%;
  348.     border: 1px solid #e8e8e8;
  349.     border-collapse: collapse;
  350.   }
  351.   .theadCla>tr>th {
  352.     padding: 10px;
  353.     color: rgba(0, 0, 0, 0.85);
  354.     border: 1px solid #e8e8e8;
  355.     background: #fafafa;
  356.     font-weight: normal;
  357.   }
  358.   tbody>tr>td,
  359.   th {
  360.     text-align: center;
  361.     font-weight: normal;
  362.     color: rgba(0, 0, 0, 0.65);
  363.     /* padding: 15px 10px; */
  364.     border: 1px solid #e8e8e8;
  365.     font-size: 12px;
  366.   }
  367.   tr:nth-child(even) {
  368.     /* background: #effefd; */
  369.   }
  370.   td {
  371.     font-size: 15px;
  372.   }
  373.   .input-cla {
  374.     width: 100%;
  375.     // border: 1px solid #888888;
  376.     height: 30px;
  377.     padding: 10px;
  378.     box-sizing: border-box;
  379.     align-items: center;
  380.     text-align: center;
  381.     justify-content: center;
  382.     :deep(.uni-easyinput__content-input) {
  383.       height: 20px;
  384.       font-size: 14px;
  385.       width: 40px;
  386.     }
  387.     :deep(.uni-easyinput__content) {
  388.       height: 20px;
  389.       font-size: 14px;
  390.       width: 100%;
  391.     }
  392.     :deep(.uni-easyinput) {
  393.       height: 20px;
  394.       font-size: 14px;
  395.       flex: 0;
  396.       width: 40px !important;
  397.     }
  398.     :deep(.uni-input-input) {
  399.       font-size: 11px !important;
  400.     }
  401.     :deep(.uni-easyinput__content-input) {
  402.       height: 20px !important;
  403.     }
  404.   }
  405.   .cus-tab {
  406.     :deep(.uni-forms-item) {
  407.       margin-bottom: 0px !important;
  408.     }
  409.   }
  410.   .input-text-cla {
  411.     padding: 10px 5px;
  412.     padding-bottom: 20px;
  413.     box-sizing: border-box;
  414.   }
  415.   .tips-clas {
  416.     flex-direction: column;
  417.     color: red;
  418.     align-items: flex-start;
  419.     gap: 5px;
  420.     font-size: 14px;
  421.     padding: 10px;
  422.     box-sizing: border-box;
  423.   }
  424.   .bot-box {
  425.     width: 100%;
  426.     padding: 10px;
  427.     padding-top: 5px;
  428.     box-sizing: border-box;
  429.     :deep(.wd-button) {
  430.       width: 90%;
  431.       display: block;
  432.       margin: 0 auto;
  433.     }
  434.   }
  435. </style>
复制代码
后端处置惩罚模版数据

之前写过类似的,就直接拿来用了,传送门
前端案例

   前端利用的uniapp+vue3+ts+vite
moduleCache中需要存放你的vm模版中的组件及api差不类似运行时的东西,不然标签是不会被剖析的,类似下面中的uni-ui的组件,假如不引入就不会被剖析,注意:引入的模版key要与vm模板中的名称同等
  1. <template>
  2.         <!-- <div style=" margin: 0; padding: 0;overflow-y: scroll;"> -->
  3.                 <component :is="dynamicComponent" v-if="templateStr"></component>
  4.                 <wd-status-tip image="comment" tip="暂无报告数据~" v-else/>
  5.                 <Fab ref="fabRef" @selectAr="selectAr" />
  6.         <!-- </div> -->
  7. </template>
  8. <script setup lang="ts" name="CalendarYear">
  9.         import { onLoad } from '@dcloudio/uni-app'
  10.         import uniForms from '@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue'
  11.         import uniFormsItem from '@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.vue'
  12.         import uniDataCheckbox from '@dcloudio/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue'
  13.         import uniEasyinput from '@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.vue'
  14.         import { abnormalReport } from '@/api/speExamineResService'
  15.         import { loadModule } from "vue3-sfc-loader/dist/vue3-sfc-loader"
  16.         import wdCheckbox from 'wot-design-uni/components/wd-checkbox/wd-checkbox.vue'
  17.         import wdButton from 'wot-design-uni/components/wd-button/wd-button.vue'
  18.         import * as Vue from 'vue'
  19.         import Fab from '@/components/Fab/index.vue'
  20.         import { compile } from 'sass';
  21.         import useUserStore from "@/store/user";
  22.         const fabRef = ref()
  23.         const proxy = getCurrentInstance()?.proxy
  24.         const dynamicComponent = shallowRef();
  25.         const templateStr = ref('')
  26.         const archiveInfo = computed(() => {
  27.                 return useUserStore().getSelectArchive()
  28.         })
  29.         const reportFun = (val : any) => {
  30.                 if (!val.archivesId) {
  31.                         proxy.$pop.toast('请选择学生')
  32.                         nextTick(() => {
  33.                                 fabRef.value.openAr()
  34.                         })
  35.                         return;
  36.                 }
  37.                 console.log('uniForms', uniForms)
  38.                 abnormalReport(val.archivesId).then(async (res : any) => {
  39.                         console.log(res)
  40.                         templateStr.value = res.data
  41.                         const options = {
  42.                                 moduleCache: {
  43.                                         vue: Vue,
  44.                                         'uniForms': uniForms,
  45.                                         'uniFormsItem': uniFormsItem,
  46.                                         'uniEasyinput': uniEasyinput,
  47.                                         'wdCheckbox': wdCheckbox,
  48.                                         'wdButton': wdButton,
  49.                                         'scss': (source) => {
  50.                                                 console.log('======>source',source)
  51.                                                 return Object.assign(compile(source), { deps: () => [] })
  52.                                         }
  53.                                 },
  54.                                 async getFile() {
  55.                                         return res.data
  56.                                 },
  57.                                 addStyle(textContent) {
  58.                                         console.log('textContent,', textContent)
  59.                                         const style = Object.assign(document.createElement('style'), { textContent })
  60.                                         console.log('style,', style)
  61.                                         const ref = document.head.getElementsByTagName('style')[0] || null
  62.                                         document.head.insertBefore(style, ref)
  63.                                 },
  64.                                 loader: {
  65.                                        
  66.                                 }
  67.                         };
  68.                         dynamicComponent.value = defineAsyncComponent(() => loadModule(res.fileName || "loader.vue", options))
  69.                 })
  70.         }
  71.         const selectAr = async (val : any) => {
  72.                 reportFun(val)
  73.         }
  74.         onLoad(() => {
  75.                 reportFun(archiveInfo.value)
  76.         })
  77. </script>
  78. <style lang="scss">
  79. </style>
复制代码
页面效果图



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

南飓风

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表