uploaddata.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view v-if="!loading && !onlyShow">
  15. <view style="margin: 40rpx;">
  16. <uni-forms :modelValue="formData" validate-trigger="bind" err-show-type="undertext" label-width="150">
  17. <uni-forms-item name="play_number" label="小眼睛阅读数/播放量">
  18. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.play_number"
  19. placeholder="输入">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="like_number" label="点赞数">
  23. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.like_number"
  24. placeholder="输入">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <uni-forms-item name="collect_number" label="收藏数">
  28. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.collect_number"
  29. placeholder="输入">
  30. </uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="comment_number" label="评论数">
  33. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.comment_number"
  34. placeholder="输入">
  35. </uni-easyinput>
  36. </uni-forms-item>
  37. </uni-forms>
  38. </view>
  39. <view style="margin: 0 40rpx;">
  40. <p style="font-size: 14px;margin-bottom: 20rpx;">上传小眼睛阅读数/播放量截图</p>
  41. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  42. @chooseSuccess="ceshiChooseSuccess1">
  43. </htz-image-upload>
  44. </view>
  45. <view class="signup">
  46. <button type="default" class="but1" :loading="loading" @click="submit()">
  47. 提交数据</button>
  48. </view>
  49. </view>
  50. <view v-if="!loading && onlyShow">
  51. <view style="margin: 20rpx;">
  52. <view style="display: flex;margin-bottom: 10rpx;">
  53. <view style="width: 400rpx;">小眼睛阅读数/播放量</view>
  54. <view style="width: 100rpx;border: 1rpx;">{{formData.show_play_number}}</view>
  55. </view>
  56. <view style="display: flex;margin-bottom: 10rpx;">
  57. <view style="width: 400rpx;">点赞数</view>
  58. <view style="width: 100rpx;border: 1rpx;">{{formData.show_like_number}}</view>
  59. </view>
  60. <view style="display: flex;margin-bottom: 10rpx;">
  61. <view style="width: 400rpx;">收藏数</view>
  62. <view style="width: 100rpx;border: 1rpx;">{{formData.show_collect_number}}</view>
  63. </view>
  64. <view style="display: flex;margin-bottom: 10rpx;">
  65. <view style="width: 400rpx;">评论数</view>
  66. <view style="width: 100rpx;border: 1rpx;">{{formData.show_comment_number}}</view>
  67. </view>
  68. <!-- 图片 -->
  69. <view style="margin-top: 10rpx;">
  70. <p>小眼睛阅读数/播放量截图</p>
  71. <image :src="imageData" mode="aspectFit"></image>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import mvBar from "@/components/mys_navBar/mysNavBar";
  79. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  80. import getPolicyEncode from '@/components/obs/getPolicy.js';
  81. import getSignature from '@/components/obs/GetSignature.js';
  82. import {
  83. fansview
  84. } from '@/components/utils.js';
  85. export default {
  86. components: {
  87. mvBar,
  88. htzImageUpload,
  89. },
  90. data() {
  91. return {
  92. onlyShow: false,
  93. loading: true,
  94. navH: getApp().globalData.navHeight,
  95. taskId: "",
  96. dataStatus: "",
  97. imageData: [],
  98. formData: {
  99. play_number: "",
  100. like_number: "",
  101. collect_number: "",
  102. commet_number: "",
  103. show_play_number: "",
  104. show_like_number: "",
  105. show_collect_number: "",
  106. show_commet_number: "",
  107. },
  108. // rules: {
  109. // // 对play_number字段进行必填验证
  110. // play_number: {
  111. // rules: [{
  112. // required: true,
  113. // errorMessage: '10位以内的数字',
  114. // },
  115. // {
  116. // minLength: 1,
  117. // maxLength: 10,
  118. // errorMessage: '10位以内的数字',
  119. // }
  120. // ]
  121. // },
  122. // // 对like_number字段进行必填验证
  123. // like_number: {
  124. // rules: [{
  125. // required: true,
  126. // errorMessage: '10位以内的数字',
  127. // },
  128. // {
  129. // minLength: 1,
  130. // maxLength: 10,
  131. // errorMessage: '10位以内的数字',
  132. // }
  133. // ]
  134. // },
  135. // // 对collect_number字段进行必填验证
  136. // collect_number: {
  137. // rules: [{
  138. // required: true,
  139. // errorMessage: '10位以内的数字',
  140. // },
  141. // {
  142. // minLength: 1,
  143. // maxLength: 10,
  144. // errorMessage: '10位以内的数字',
  145. // }
  146. // ]
  147. // },
  148. // // 对comment_number字段进行必填验证
  149. // comment_number: {
  150. // rules: [{
  151. // required: true,
  152. // errorMessage: '10位以内的数字',
  153. // },
  154. // {
  155. // minLength: 1,
  156. // maxLength: 10,
  157. // errorMessage: '10位以内的数字',
  158. // }
  159. // ]
  160. // }
  161. // },
  162. mysNavConfig: {
  163. /* 开启单页显示首页图标 */
  164. isHome: true,
  165. /* 固定导航 */
  166. navFixed: true,
  167. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  168. navTitle: {
  169. text: "上传数据",
  170. color: "",
  171. fontSize: "32rpx", // px upx rpx
  172. fontWeight: "normal", // 100 - 700
  173. },
  174. btnType: "type2",
  175. onLeftClick: '',
  176. /* type2 按钮 */
  177. type2Config: {
  178. // 左图标
  179. leftPath: "/static/img/png2.png",
  180. // 右图标
  181. rightPath: "/static/img/png4.png",
  182. // 圆角
  183. radius: "40rpx",
  184. },
  185. },
  186. }
  187. },
  188. onLoad(options) {
  189. let data = options.textObj.replace(/""/g, "");
  190. data = JSON.parse(decodeURIComponent(data))
  191. this.taskId = data.taskId
  192. this.dataStatus = data.dataStatus
  193. this.getData()
  194. },
  195. methods: {
  196. async getData() {
  197. this.loading = true
  198. uni.showLoading({
  199. title: '加载中'
  200. });
  201. await this.$https.get('/youngee/c/t/g/get-unsubmit-task-data' +
  202. "?" +
  203. "task_id" +
  204. "=" +
  205. this.taskId)
  206. .then(res => {
  207. console.log(res)
  208. if (res.data.data != null) {
  209. this.onlyShow = true
  210. this.formData.play_number = res.data.data.play_number
  211. this.formData.like_number = res.data.data.like_number
  212. this.formData.collect_number = res.data.data.collect_number
  213. this.formData.comment_number = res.data.data.comment_number
  214. this.formData.show_play_number = fansview(this.formData.play_number)
  215. this.formData.show_like_number = fansview(this.formData.like_number)
  216. this.formData.show_collect_number = fansview(this.formData.collect_number)
  217. this.formData.show_comment_number = fansview(this.formData.comment_number)
  218. this.imageData.push(res.data.data.photo_url)
  219. }
  220. })
  221. uni.hideLoading();
  222. this.loading = false
  223. },
  224. toRecord() {
  225. var data = {
  226. taskId: this.taskId,
  227. };
  228. data = JSON.stringify(data)
  229. uni.navigateTo({
  230. url: '/pages/workspace/datarecord?textObj=' + encodeURIComponent(data)
  231. });
  232. },
  233. submit() {
  234. // 校验
  235. if (this.formData.play_number == "" || this.formData.like_number == "" || this.formData.collect_number ==
  236. "" || this.formData.comment_number == "") {
  237. uni.showToast({
  238. title: '请输入10位以内的数字',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. if (this.imageData.length == 0) {
  244. uni.showToast({
  245. title: "请上传正确的截图",
  246. icon: 'none'
  247. })
  248. return
  249. }
  250. let that = this
  251. uni.showModal({
  252. title: '提示',
  253. content: '提交后无法修改并进行审核,确认提交?',
  254. success: async function(res) {
  255. if (res.confirm) {
  256. // 调用添加数据接口
  257. await that.$https.post('/youngee/c/t/p/add-task-data', {
  258. task_id: that.taskId,
  259. play_number: that.formData.play_number,
  260. like_number: that.formData.like_number,
  261. collect_number: that.formData.collect_number,
  262. comment_number: that.formData.comment_number,
  263. photo_url: that.imageData[0],
  264. })
  265. .then(res => {
  266. console.log(res)
  267. })
  268. await that.$https.get('/youngee/c/t/g/submit-task-data' +
  269. "?" +
  270. "task_id" +
  271. "=" +
  272. that.taskId)
  273. .then(res => {
  274. console.log(res)
  275. })
  276. uni.navigateBack()
  277. } else if (res.cancel) {
  278. console.log('用户点击取消');
  279. }
  280. }
  281. });
  282. },
  283. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  284. console.log('ceshiChooseSuccess', tempFilePaths, e);
  285. if (e == 0) {
  286. this.store = 'talent_upload/' + this.guid() + '.png'
  287. } else if (e == 1) {
  288. this.store = 'talent_upload/' + this.guid() + '.mp4'
  289. }
  290. /****************
  291. 以下代码是自定义上传逻辑,仅供参考
  292. ***************/
  293. this.imgUpload1(tempFilePaths);
  294. /*******************************/
  295. console.log("imgdata" + this.imageData)
  296. },
  297. imgUpload1(tempFilePaths) {
  298. let that = this
  299. console.log('imgUpload', tempFilePaths)
  300. let config = {
  301. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  302. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  303. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  304. };
  305. let fileName = this.store; //指定上传到OBS桶中的对象名
  306. // let fileName = "talent_upload/icon-arrow-right.png"
  307. let OBSPolicy = { //设定policy内容
  308. "expiration": "2089-12-31T12:00:00.000Z",
  309. "conditions": [{
  310. "bucket": "horastar"
  311. }, //Bucket name
  312. // {"bucket": "goin"},
  313. {
  314. 'key': fileName
  315. }
  316. ]
  317. }
  318. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  319. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  320. uni.uploadFile({
  321. //url: config.EndPoint,
  322. url: config.EndPoint,
  323. filePath: tempFilePaths[0],
  324. name: 'file',
  325. formData: {
  326. 'AccessKeyID': config.AccessKeyId,
  327. 'policy': policyEncoded,
  328. 'signature': signature,
  329. 'key': fileName,
  330. },
  331. success: function(res) {
  332. console.log(res.statusCode); //打印响应状态码
  333. if (res.statusCode == '204') {
  334. that.imageData.push(config.EndPoint + '/' + fileName);
  335. console.log('上传图片成功', res)
  336. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  337. console.log(obs_url)
  338. // that.formData.home_img = obs_url
  339. uni.showToast({
  340. title: '上传成功',
  341. icon: '成功'
  342. });
  343. } else {
  344. console.log('上传图片失败', res)
  345. uni.showToast({
  346. title: '上传失败',
  347. icon: '失败'
  348. });
  349. }
  350. },
  351. fail: function(e) {
  352. console.log(e);
  353. uni.showToast({
  354. title: '上传失败22222',
  355. icon: '失败'
  356. });
  357. }
  358. })
  359. },
  360. guid() {
  361. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  362. var r = Math.random() * 16 | 0,
  363. v = c == 'x' ? r : (r & 0x3 | 0x8);
  364. return v.toString(16);
  365. });
  366. },
  367. }
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. .signup {
  372. box-shadow: 0rpx 5rpx 40rpx #ccc;
  373. width: 100%;
  374. position: fixed;
  375. bottom: 0rpx;
  376. display: flex;
  377. height: 90rpx;
  378. padding-top: 2%;
  379. background-color: #FFFFFF;
  380. }
  381. .but1 {
  382. width: 60%;
  383. background-color: #f2d22d;
  384. border-radius: 20rpx;
  385. font-size: 36rpx;
  386. line-height: 200%;
  387. letter-spacing: 10rpx;
  388. font-weight: 500;
  389. height: 80%;
  390. &.on {
  391. background-color: #C0C0C0;
  392. }
  393. }
  394. </style>